Remove default JFrame icon

ⅰ亾dé卋堺 提交于 2019-11-28 07:41:33

问题


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


回答1:


Create icon that consists of one pixel (better transparent) and use it. If you need such icon contact me. I will send you.




回答2:


It's always good to keep a copy of the Java source code around. The code for java.awt.Window (a superclass of JFrame) has the following code for 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:

Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
myFrame.setIconImage(icon);



回答3:


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.




回答4:


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:

ImageIcon frameIcon = new ImageIcon("files\yourfile.png");
frame.setIconImage(frameIcon.getImage());

Should be fine.



来源:https://stackoverflow.com/questions/6868928/remove-default-jframe-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!