java 修改我的 .jar 程序的任务栏图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10575541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modifying taskbar icon of my .jar program
提问by Rohit Malish
I'm trying to change the default java icon that appears in taskbar everytime I run my .jar program. I managed to change it with frame.setIconImage(img); but this makes icon way too small, I want it to be as big as other programs icons and have a high quality. Any way I can do that? Thanks.
我试图更改每次运行我的 .jar 程序时出现在任务栏中的默认 java 图标。我设法用 frame.setIconImage(img); 改变它。但这使得图标太小了,我希望它和其他程序图标一样大并且具有高质量。我有什么办法可以做到吗?谢谢。
回答by a_horse_with_no_name
As you only supplied a singleicon, Windows will then scalethat icon to whatever size it needs displaying it in the taskbar (could be 16x16, 32x32 or other sizes, depending on the desktop them and size of the taskbar.
由于您只提供了一个图标,因此 Windows 会将该图标缩放到它需要在任务栏中显示的任何大小(可能是 16x16、32x32 或其他大小,具体取决于桌面和任务栏的大小)。
If you want to have a "good looking" icon in the task bar you will need to provide a 32x32 pixel version of your icon.
如果您想在任务栏中有一个“好看”的图标,您需要提供一个 32x32 像素版本的图标。
Once you have that you can call setIconImages(List)
instead of setIconImage()
to define the icons that the operating system can use:
一旦你有了它,你就可以调用setIconImages(List)
而不是setIconImage()
定义操作系统可以使用的图标:
List<Image> icons = new ArrayList<Image>();
icons.add(getImage("someImage16x16.gif"));
icons.add(getImage("someImage32x32.gif"));
window.setIconImages(icons);
Where getImage()
is some method returning the proper image icon. Essentially that would be the same steps you already used to define the current icon.
哪里getImage()
有返回正确图像图标的方法。本质上,这与您已经用于定义当前图标的步骤相同。
You can also supply a 64x64 and 24x24 icon using this method (just add more icons to the list).
您还可以使用此方法提供 64x64 和 24x24 图标(只需向列表中添加更多图标)。
回答by kentcdodds
Try looking at this example. It looks like you need to use frame.setIconImage(Toolkit.getDefaultToolkit().getImage("your_image.gif"));
line
试试看这个例子。看起来你需要使用frame.setIconImage(Toolkit.getDefaultToolkit().getImage("your_image.gif"));
line