Remove default JFrame icon

前端 未结 4 1254
慢半拍i
慢半拍i 2020-12-19 07:41

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 r

相关标签:
4条回答
  • 2020-12-19 07:51

    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 讨论(0)
  • 2020-12-19 07:52

    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);
    
    0 讨论(0)
  • 2020-12-19 08:05

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

    0 讨论(0)
  • 2020-12-19 08:06

    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.

    0 讨论(0)
提交回复
热议问题