0

I using Eclipse to export a runnable JAR file from my project file. But the icon image never shows after export. It works when I run through eclipse but not after creating the JAR.

Here is my code that I have in my main method:

frame.setIconImage(Toolkit.getDefaultToolkit().getImage("images/icon.gif"));

Image is the correct directory. Also, tried method using BufferedImage but did not work.

Thanks in advance for your help.

exlux15
  • 909
  • 1
  • 9
  • 16

2 Answers2

5

images in a JAR file are treated as resources. You need to use

getClass().getResource("images/icon.gif")

and then use ImageIcon or other techniques to get the image. See:

How to includes all images in jar file using eclipse

Community
  • 1
  • 1
Vijay Agrawal
  • 3,751
  • 2
  • 23
  • 25
1

An example of how I did:

    Image image =Toolkit.getDefaultToolkit().getImage(getClass().getResource("wood.jpg"));

The above method worked for me when creating a runnable jar.

Hope it helps.

MRSGT _GT
  • 246
  • 2
  • 11