Link to home
Start Free TrialLog in
Avatar of morti
morti

asked on

Image in JAR not found/used

I have a gif image that is called by a JLabel:

JPanel cp = new JPanel(new GridLayout(0,2));
cp.add(new JLabel(new ImageIcon("test.gif")));

I produced a jar by using this command: "jar cvfm MyApp.jar manifest.txt *.class test.gif"

The jar is correctly created and the image is shown if the jar is run in a directory that contains "test.gif" (the contents of the directory are MyApp.jar and test.gif). If the gif isn't in the same directory, the image won't show. What am I doing wrong?

Thank you! :)
SOLUTION
Avatar of suprapto45
suprapto45
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morti
morti

ASKER

My solution was similar:

cp.add(new JLabel(new ImageIcon( this.getClass().getResource("/test.gif")) ));
:-)