I'm using the Netbeans IDE and when I use the "Clean and Build Project" to make an executable jar file of my program, it doesn't keep the images. I have the images located in "src/resources".
I am getting the images though code the following way:
setIcon(new javax.swing.ImageIcon(getClass().getResource("icon.png")));
How do I get the images to show up in the executable jar file?
如果您的图片位于src / resources中,则用于设置图片文件的代码行应如下所示
setIcon(new javax.swing.ImageIcon(getClass().getResource("resources/icon.png")));
Try using the path /resources/icon.png
. Remember, when you use getClass().getResource
with a relative path, the path will be relative to the class's package, not it's root.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.