I’d like to load an image to my program, but in away that my runnable jar will also be able to do so.
So new ImageIcon(URL); to JLabel doesn’t really work.
All my java files are in src folder, in core package. I’d like to put my picture to src folder, but inside images package.
Is that possible, or do I have to put my image to specific location inside my project?
And what would be a way to load image into my program so it works inside a runnable jar?
The way I usually embed imagery inside Java Jar files is I have a package in my
srcfolder that contains all of my image files plus a single class calledResource. The class code is similar to the following:Provided the
Resourceclass and all of your image files reside in the same package, all you have to do is create a newJLabelwith theImageIconreturned by callingloadIcon([simple filename]). This will work regardless of whether you’re running in an IDE or from a Jar file.