Alex Rivera | Logout

Add image to JAR Java

Asked 2009-07-08T06:29:26.137
24

I'm using some images in JFrame, I have given a path to load image into panel of the frame, but when i made jar of the application its not displaying images.
Where should I place the image?
How should I specify the path?

setIconImage(Toolkit.getDefaultToolkit().getImage(
                "D:\\RFT\\src\\dailogBox\\dump.jpg"));

like this i have done.

Edit
Report

1 Answer

-2

The easy way to do this is to have the folder your image is in parallel to the jar file. Example:

Say in the code you call the image like this:

pic = new ImageIcon("Pics/buttonpic.jpg");

This means your picture would be called buttonpic and is located in a folder called Pics in your project directory. Now after you make your jar file, copy that Pics folder into the same folder your jar file is located.

Example: if your jar file is located on your desktop, then put the Pics folder on the desktop. Now when you run the jar file, your pictures will work correctly. Now to cover up the fact that you need to have your Pics folder next to your jar file, you can create a new folder and place in that folder your jar and the Pics folder. Then right click the jar and create a shortcut, then place that shortcut on the desktop or where you wanted to have just the jar file, and place the new folder you created wherever you want to hide it at.

answered 2010-08-09T15:36:11.613

Your Answer