Java Jar question

Kindez

n00b
Joined
Apr 13, 2006
Messages
8
I have built a Swing GUI and wish to distribute it as a jar file. I used icons for some buttons, and would like to put the icon images in the jar file (know how to do this) and have my code reference said images (do not know how to do this).

This is the code I use to place the icon image on the button
Code:
pause.setIcon(new ImageIcon("pause.png"));

I know that I can place the images in the jar file with the command
Code:
jar -cvmf manifest.txt gui.jar *.class *.png

For cliffs, my question is; How do I find the images in the jar file so that my GUI runs with visible buttons?
 
Try this:

Code:
URL pauseImage = gui.class.getResource("pause.png");
pause.setIcon(new ImageIcon("pause.png"));

You need to create a jar file with your images before you compile though.

--KK
 
Got it working with

Code:
pause.setIcon(new ImageIcon(getClass().getResource("pause.png")));
 
Back
Top