java 删除默认的 JFrame 图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6868928/
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
Remove default JFrame icon
提问by Kaushik Balasubramanain
In my JFrame i have the default coffee icon. I want to remove it. But when i do setIconImage(null) it does't work. Can anyone tell me the solution as to how to completely remove the icon
在我的 JFrame 中,我有默认的咖啡图标。我想删除它。但是当我执行 setIconImage(null) 时它不起作用。谁能告诉我有关如何完全删除图标的解决方案
采纳答案by AlexR
Create icon that consists of one pixel (better transparent) and use it. If you need such icon contact me. I will send you.
创建由一个像素(更好的透明)组成的图标并使用它。如果您需要这样的图标,请联系我。我会送你。
回答by Paul
It's always good to keep a copy of the Java source codearound. The code for java.awt.Window (a superclass of JFrame) has the following code for setIconImage
:
保留一份Java 源代码的副本总是好的。java.awt.Window(JFrame 的超类)的代码具有以下代码setIconImage
:
public void setIconImage(Image image)
{
ArrayList<Image> imageList = new ArrayList<Image>();
if (image != null)
{
imageList.add(image);
}
setIconImages(imageList);
}
You can see that passing in a null image is the same as doing nothing so you'll have to pass in an image to get rid of the coffee cup. As others have suggested using a 1 x 1 transparent icon is your best bet. Here is some code to create the icon:
你可以看到传入一个空图像与什么都不做是一样的,所以你必须传入一个图像才能摆脱咖啡杯。正如其他人所建议的那样,使用 1 x 1 透明图标是您最好的选择。下面是一些创建图标的代码:
Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
myFrame.setIconImage(icon);
回答by jazzdawg
You can set the image icon to a transparent image which will remove the coffee cup. I don't believe it is possible to get rid of the default icon otherwise.
您可以将图像图标设置为透明图像,这将移除咖啡杯。我不相信有可能以其他方式摆脱默认图标。
回答by Zi1mann
You could just use gimp or photoshop or even paint and create a 1x1px, transparent image, export it (.png or .jpg, doesnt matter?). Then apply it:
您可以只使用 gimp 或 photoshop 甚至绘画并创建一个 1x1px 的透明图像,然后将其导出(.png 或 .jpg,无所谓?)。然后应用它:
ImageIcon frameIcon = new ImageIcon("files\yourfile.png");
frame.setIconImage(frameIcon.getImage());
Should be fine.
应该没事。