aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes where to put image jar files    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "where to put image jar files    " Watch "where to put image jar files    " New topic
Author

where to put image jar files

Nidhi Nagre
Ranch Hand

Joined: Nov 05, 2007
Posts: 64
hi everyone,

actually i want to change the icon of JFrame window

now, jarred that icon image( it is of PNG type) named icons.jar without any subdirectory in it. i tried loading this image after putting this jar file in applets class files directory using this method





but it has not been get loded.
where should i put the jar file?

any help is greatly appreciated
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

You can only use getClass().getResource() if the resource is in the exact same place as the class. Therefore, the image itself should be in the JAR file with the class itself.

If you want to load it from the JAR anyway, you need to create a URL that looks like "jar:file:<location to JAR file>!icon1.JPG".

You can create this as follows, given that you have a File object to the JAR file:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nidhi Nagre
Ranch Hand

Joined: Nov 05, 2007
Posts: 64
it is definitely highly appreciating, the way you have just given to use.
but rather i have still a quary and i hope it will be erased


Rob Prime wrote:
You can only use getClass().getResource() if the resource is in the exact same place as the class. Therefore, the image itself should be in the JAR file with the class itself.


you meant to say that, the applet class file must be jarred along with the image file. and the i can access directly this image from within jarred applet class, isn't it?

any way, i have tried without using jar file. just given the image file path as argument to ImageIO.read() method. but i got a strange thing, the image file was taking a long to load (even though is was not loaded)and i couldn't figure out what was occuring in background.

can you figure it out, what was the problem?

thanks

[ November 28, 2007: Message edited by: Nidhi Nagre ]
[ November 28, 2007: Message edited by: Nidhi Nagre ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

Originally posted by Nidhi Nagre:
you meant to say that, the applet class file must be jarred along with the image file. and the i can access directly this image from within jarred applet class, isn't it?

If you don't JAR the applet class file, you don't need to JAR the image file. Just put it in the same folder.

If you JAR the applet class file, include the image file inside that same JAR file, in the same folder as the applet class file.
Nidhi Nagre
Ranch Hand

Joined: Nov 05, 2007
Posts: 64

Rob prime wrote:
If you don't JAR the applet class file, you don't need to JAR the image file. Just put it in the same folder.


but, even after putting image file in same folder, the method getClass().getResources() was not able to access the image file, instead it flushed java.lang.classnotfoundexception, why??

in your 1st reply, you probabbly meant to say that if image file has not been jarred with applet class file then, instead, without using getClass().getResources method the image file can be acced simply by



but using this i got javax.imageio.IIOutputException

is it due to .PNG ? any other reason?

thanks

[ November 29, 2007: Message edited by: Nidhi Nagre ]
[ November 29, 2007: Message edited by: Nidhi Nagre ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

To be safe, create a URL based on the location of the HTML page:

This code should be placed inside the applet itself, otherwise you need either a reference to the applet to get access to the getDocumentBase() method, or a reference to the document base itself.

You can use getCodeBase() for the location of the class file if needed.
Nidhi Nagre
Ranch Hand

Joined: Nov 05, 2007
Posts: 64
i followed your way, but this time i got something strange,that instead if displaying image, something was running in background seemings for a long time. try to close the applet window was not making any effect too.

after closing it using window task manager,i got the following at java console



i cant figure, what is this mean?

by the way i am using the code


[ November 29, 2007: Message edited by: Nidhi Nagre ]
Nidhi Nagre
Ranch Hand

Joined: Nov 05, 2007
Posts: 64
please help me, its urgent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where to put image jar files