views:

121

answers:

3

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.

+1  A: 

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
+1  A: 

check out this link

Arivu2020
@Arivu Thanks for the link. I got the answer.
Samurai