0

I'm using the Netbeans IDE and when I use the "Clean and Build Project" to make an executable jar file of my program, it doesn't keep the images. I have the images located in "src/resources".

I am getting the images though code the following way:

setIcon(new javax.swing.ImageIcon(getClass().getResource("icon.png")));

How do I get the images to show up in the executable jar file?

josmek
  • 211
  • 4
  • 8
  • almost duplicate post: http://stackoverflow.com/questions/14596487/imageicons-on-jbutton-are-not-showing-up-in-runnable-jar-file – Kostas Kryptos May 05 '14 at 21:58
  • @KonstantinosChalkias I've tried that they said in that post and none of it seems to work for me :\ – josmek May 05 '14 at 22:09

2 Answers2

0

If your image is located in src/resources your line of code to set the image file should be like this

setIcon(new javax.swing.ImageIcon(getClass().getResource("resources/icon.png")));
Alan
  • 243
  • 1
  • 11
  • What are you trying to set an image to? A JLabel? I think it might help if you posted more of you're code. – Alan May 05 '14 at 22:24
0

Try using the path /resources/icon.png. Remember, when you use getClass().getResource with a relative path, the path will be relative to the class's package, not it's root.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366