Hello everyone. I am running into a small bit of difficulty with images I want to use in a Java program, keeping them bundled with the program in a JAR file and accessing them within the package.
For those who are thinking it, this is definitely not homework.
In my program, I have several images I would like to use on buttons on a toolbar. I am under the impression
Code:
JButton button = new JButton(new ImageIcon("icon.png"));
is referencing the filesystem (the directory location where the JAR exists) but what I want is to be able to access the resource within the JAR. Further explanation: if the JAR I am running is located at /home/indienick/program.jar, the ImageIcon class is (probably) looking for the image at /home/indienick/icon.png.
I have Googled, and I found something that comes close, but it deals with fetching images from a URL - nothing that deals with local files, more specifically, local images kept inside of a JARchive.
Any help would be greatly appreciated.