[英]Remove default JFrame icon
In my JFrame i have the default coffee icon. 在我的JFrame中,我具有默认的咖啡图标。 I want to remove it. 我要删除它。 But when i do setIconImage(null) it does't work. 但是当我做setIconImage(null)时,它不起作用。 Can anyone tell me the solution as to how to completely remove the icon 谁能告诉我有关如何完全删除图标的解决方案
It's always good to keep a copy of the Java source code around. 保留Java源代码的副本总是很好。 The code for java.awt.Window (a superclass of JFrame) has the following code for setIconImage
: 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. 正如其他人建议的那样,使用1 x 1透明图标是您的最佳选择。 Here is some code to create the icon: 这是一些创建图标的代码:
Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
myFrame.setIconImage(icon);
Create icon that consists of one pixel (better transparent) and use it. 创建由一个像素(更好地透明)组成的图标并使用它。 If you need such icon contact me. 如果您需要这样的图标,请与我联系。 I will send you. 我会寄给你。
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. 我认为否则无法摆脱默认图标。
You could just use gimp or photoshop or even paint and create a 1x1px, transparent image, export it (.png or .jpg, doesnt matter?). 您可以只使用gimp或photoshop,甚至可以绘画并创建一个1x1px的透明图像,然后将其导出(.png或.jpg,没关系吗?)。 Then apply it: 然后应用它:
ImageIcon frameIcon = new ImageIcon("files\yourfile.png");
frame.setIconImage(frameIcon.getImage());
Should be fine. 应该没事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.