在Jar文件中设置图标图像 [英] Set Icon Image in Jar file

查看:239
本文介绍了在Jar文件中设置图标图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在NetBeans上运行时工作正常。

The following code works fine when running on NetBeans.

this.getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage("PlagiaLyzerIcon.png"));

然而,一旦它被内置到Jar文件中,图标就消失了。

However, once it was built into Jar file, the icon was gone.

任何人都知道这是什么问题?我意识到我要将图标图像放在根目录上,但是,在编译成JAR之后,图标就消失了。

Anyone has idea what's the problem? I realized I've to put the icon image on the root directory, however, after compiling into JAR, the icon gone.

感谢您的帮助...

大家好,问题已通过以下代码解决,

Hi everyone, the problem was solved with the following code,

 this.getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("plagialyzer/resources/PlagiaLyzerIcon.png")));

一旦编译成jar文件就可以工作。

It works once compiled into jar file.

推荐答案

使用

this.getFrame().setIconImage(
new imageIcon(getClass().getClassLoader().getResource("PlagiaLyzerIcon.png"))
);

而不是。

注意:

此行仅在图像位于jar文件的根目录中时才有效。如果没有,你必须在字符串上指定文件夹:

this line only works if the images are in the root of the jar file. If not, you have to specify the folder on the string:

getResource("yourfolder/PlagiaLyzerIcon.png")

这篇关于在Jar文件中设置图标图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆