aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Image is not getting displayed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image is not getting displayed" Watch "Image is not getting displayed" New topic
Author

Image is not getting displayed

shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
I want to display an image in the applet..Can anyone say me how to do that..And i want to display the label at specified co-ordinates..How can i do this..

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
I want to reduce the size of the image..How can i do it?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Changes:
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
I'm working in NetBeans..I exectued the program..Its working well with applet viewer but in IE...I checked the permission too..Everything is well but still its not displaying in IE..What might be the reason?
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
Its saying that Applet loading failed..
The IE is not accepting the image file(GIF)..What should i have to do to display the image in IE?Please help me..

[ November 13, 2007: Message edited by: shalini gnana ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
Originally posted by shalini gnana:
Its saying that Applet loading failed..

Why does applet loading fail - there should be an exception in the Java Console - what does it say?
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
My image is not getting loaded..If i comment the image part then its working..

It throws the following error:

ava.security.AccessControlException: access denied (java.io.FilePermission C:\Documents and Settings\8563\JavaApplication2\image\folder.gif read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at mining.TreeEX$ImagePanel.<init>(TreeEX.java:41)
at mining.TreeEX.init(TreeEX.java:30)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
access denied (java.io.FilePermission C:\Documents and Settings\8563\JavaApplication2\image\folder.gif read)


Applets can't access the local file system. You need to rewrite the code that uses this file to load the file from the server (or the applet jar file) instead.
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
No.i'm not getting you..Can you please explain me little bit elobrately...
Please help me..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
Show us the code that uses folder.gif. Then it'll be easier to explain what's going wrong, and how to fix it.
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189


This is where i'm getting error...
Please help me..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

As said before, you can't access files on the local file system from applets unless you explicitly allow it to. You'll need to set permissions, and most likely sign the applet too.

It's better to use a relative path to the image. If your HTML file is stored in C:\Documents and Settings\8563\JavaApplication2, the following will create a relative URL for you:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
Here,myapplet is my applet class name?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
No, it's a reference to the applet instance. If this code is inside of the TreeEX class (which extends Applet) then you can just write

but if the code moves to a different class -which is the case in your code- you'll need a reference to the Applet object. You could pass that into the ImagePanel class in the constructor.
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
I tried to add in the way you said..But its throwing nullPointer Exception...

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
I tried to add in the way you said..

Actually, no, you didn't. I suggested passing a reference to the applet instance to the ImagePanel class in its constructor. What you did was to try to create a new instance of the applet class:

I mentioned to you that one should never do that in your question about Gantt charts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image is not getting displayed