Hi I am using NetBeans IDE and I have my images (what I am using in my project) in a folder named Images. When I am building jar it doesn't take that images. The code I am using to set image is,
buttonObj.setIcon(new ImageIcon("\Images\a.jpg")
any help please.
Asked
Active
Viewed 1,500 times
2

Samurai
- 843
- 6
- 23
- 44
-
How do you build your jar-file? – Peter Lang Apr 24 '10 at 10:07
-
@Peter Using NetBeans -> clean and build option. – Samurai Apr 24 '10 at 10:21
1 Answers
1
you can try with
URL loadingUrl = this.getClass().getResource("/images/a.jpg");
ImageIcon icon = new ImageIcon(loadingUrl);
using the getClass().getResource(..)
should be the correct approach to load files from a JAR. But remembers to check documentation for precise specification (if I'm not wrong it prepends the fully qualified package to the path you are loading from)

Jack
- 131,802
- 30
- 241
- 343