更改我的java应用程序的图标 [英] Changing the icon of my java application
问题描述
对于简单的Java桌面应用程序我添加了一个带有NetBeans IDE助手的JFrame表单。对于此框架,我想更改标题栏中的图标。
我尝试在生成的View类中的构造函数的最后使用以下代码执行此操作:
for a simple Java Desktop Application I added a JFrame Form with the assistant of the NetBeans IDE. For this frame I want to change the icon in the title bar. I tried to do so with the following code at the very end of the constructor in the generated View class:
ImageIcon ii = new ImageIcon(iconUrl);
this.getFrame().setIconImage(ii.getImage());
String iconUrl绝对正确,对象ii似乎没问题,据我所知调试器透视图中的变量概述。
但是,标题栏中的图标不会改变,它仍然是默认的java图标。
The String iconUrl is definitely correct, the object ii seems to be alright as far as I can judge from the variables overview in the debugger perspective. However, the icon in the title bar does not change, it's still the default java icon.
为什么?
推荐答案
你可以试试这个:
Image i = ImageIO.read(getClass().getResource("/path/to/image"));
setIconImage(i);
请注意,这里 /
代表你的 src
目录
Note that here /
would represent your src
directory
这篇关于更改我的java应用程序的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!