2

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.

Samurai
  • 843
  • 6
  • 23
  • 44

1 Answers1

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