0

So I have created a GUI application, I have set the image for each frame using this:

ImageIcon img = new ImageIcon("./Icons/icon32x32.png");
                frame.setIconImage(img.getImage());
                frame.setVisible(true);

When I run it through Eclipse, the image is being displayed successfully, but when I export the project to a .jar file it doesn't.

I have tried running the jar in both "double click" fashion and by using CMD

java -jar jarfilename.jar
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • is the icon inside the jar? – JP Moresmau Feb 14 '16 at 17:19
  • 1
    When exporting as a jar, it'll search for the image in `Icons/icon32x32.png`. Chances are that that's not where the image is when exported. You should package the image as a resource instead and reference it that way to ensure it'll work even when you export. – Deximus Feb 14 '16 at 17:19
  • Application resources will become **embedded resources** by the time of deployment, so it is wise to start accessing them as if they were, right now. An [tag:embedded-resource] must be accessed by URL rather than file. See the [info. page for embedded resource](http://stackoverflow.com/tags/embedded-resource/info) for how to form the URL. – Andrew Thompson Feb 14 '16 at 17:22

0 Answers0