Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove default JFrame 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 completely remove the icon

like image 501
Kaushik Balasubramanain Avatar asked Jul 29 '11 05:07

Kaushik Balasubramanain


People also ask

How do I remove an icon from a Jbutton?

Simple, Set the icon to null . It doesn't have an icon, so it removes it. That will work perfectly.

How do I turn off JFrame code?

The efficient way of closing the JFrame is that we use the inbuilt method provided by the JFrame class i.e., using the JFrame. setDefaultCloseOperation(int) method. We use this method to change the behavior of the default JFrame which hides it instead of disposing of it when the user closes the window.

What is J in JFrame?

JFrame is a top-level container that provides a window on the screen. A frame is actually a base window on which other components rely, namely the menu bar, panels, labels, text fields, buttons, etc. Almost every other Swing application starts with the JFrame window.


1 Answers

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);
like image 67
Paul Avatar answered Sep 21 '22 17:09

Paul