Create jar file with images and database

Hi, I am using NetBeans IDE and I have my images (which is what I use in my project) in a folder named β€œImages”. When I create a jug, it doesn't accept these images. The code I am using to set the image,          buttonObj.setIcon(new ImageIcon("\Images\a.jpg")

any help please.
+2


a source to share


1 answer


you can try with

URL loadingUrl = this.getClass().getResource("/images/a.jpg");
ImageIcon icon = new ImageIcon(loadingUrl);

      



using getClass().getResource(..)

should be the correct approach for loading files from a JAR. But remember to check the documentation for the exact specification (if I'm not mistaken it adds the complete package to the path you download)

+1


a source







All Articles