开发者

Remove default JFrame icon

开发者 https://www.devze.com 2023-03-23 13:47 出处:网络
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 comp开发者_Go百科letely remove the icon

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 comp开发者_Go百科letely remove the icon


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);


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?). Then apply it:

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

Should be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号