图片未显示在JAR文件中 [英] Images not being displayed in JAR file
本文介绍了图片未显示在JAR文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Netbeans IDE,当我使用清理并生成项目"来制作程序的可执行jar文件时,它不会保留图像.我的图片位于"src/资源"中.
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")));
如何使图像显示在可执行jar文件中?
How do I get the images to show up in the executable jar file?
推荐答案
尝试使用路径/resources/icon.png
.请记住,当您将getClass().getResource
与相对路径一起使用时,该路径将相对于类的包,而不是相对于其根.
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.
这篇关于图片未显示在JAR文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文