导出 Swing 应用程序后没有图标
我正在用 Java 编写 GUI(当然使用 Swing),在 Eclipse 中运行我的应用程序时,一切都很好,并且带有图标等,但是在导出我的应用程序后,图标就消失了。
图标位于以下目录 resources/icons
的类路径下。
JButton browseButton = new JButton("Browse", new ImageIcon("resources/icons/browse.png"));
I'm programming a GUI in Java (using Swing of course) and while running my application in Eclipse everything is fine and with icons and whatnot, but after exporting my application the icons are gone.
The icons are located under the class-path in the following directory resources/icons
.
JButton browseButton = new JButton("Browse", new ImageIcon("resources/icons/browse.png"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎按照@kleopatra 的指导,这肯定是正确的方法。
创建资源文件夹时,请确保通过右键单击项目来完成此操作,然后转到源文件夹并将其命名为资源/图标,然后手动将图像放入该文件夹中,然后返回 Eclipse 并刷新项目。现在您也可以在可运行的 jar 中使用这些图像。
现在,为了在您的类中使用您的图像/图标,请使用此
路径,您的
path
将是image
的名称,前缀为正斜杠,位于您的< code>resources/icons 文件夹,如"/myIcon.png"
在发布答案之前,我想确定一下,所以对其进行了测试。
否则请给我一些时间,我会将所有步骤放在某个地方供您查看。
与整个事情相关的更多信息可以在我的另一个答案中找到:
Load ImageIcon Exception
Seems like as guided by @kleopatra, this surely is the right way.
When you create resources folder, make sure you do it by right clicking your project, then go to source folder and name it as resources/icons and then manually put your images in that folder, and go back to your eclipse and refresh your project. Now you can use these images in your runnable jar also.
Now in order to use your image/icon in your Classes use this
Here your
path
will be the name of theimage
prefix it by a forward slash, which is inside yourresources/icons
folder like"/myIcon.png"
I wanted to be sure, before i post my answer, so tested it.
Else give me some time, I will put all steps somewhere for you to see.
More info related to the whole thingy can be found on this another answer of mine :
Load ImageIcon Exception