0

I do not want my jframe to display any icon in taskbar. Basically if we don't specify any IconImage to it, then it shows default icon. But in my program I don't want any icon to be displayed.

 setUndecorated(true);
 setSize(208, 58);
 setImageIcon(null); // same result

If I will use transparent image as Icon, even then the system will show a transluscent rectangle for icon.

enter image description here

My question is straight forward. I don't think I need to give any coding for it. If there exist any method to do that, let me know.
1 way by which it could be done is to use JWindow or Window, but there are many drawbacks for using it and I don't want to do it this way.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
afzalex
  • 8,598
  • 2
  • 34
  • 61
  • 1
    `JWindow` will also do what you want, but you will lose the window borders... – MadProgrammer Sep 09 '14 at 00:01
  • And I don't want window borders though, as you can see in my coding I have `enabeled underation`. The problem is not that.@MadProgrammer but there are many other benefits which I will lose if I use JWindow. – afzalex Sep 09 '14 at 00:18
  • `frame.setIcon(new ImageIcon(new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB))); // important part is..` **`ARGB`** Well, either that or run the code on [OS X](http://stackoverflow.com/a/21945380/418556).. ;) – Andrew Thompson Sep 09 '14 at 01:53

1 Answers1

5

One possible solution: don't display a JFrame but rather display a JDialog. Note that any complex GUI that you put in a JFrame's contentPane can be placed into a JDialog which is yet another reason to avoid create applications that subclass JFrame. For example:

import java.awt.Dimension;
import javax.swing.*;

public class TestJDialog {
   private static void createAndShowGui() {
      JDialog dialog = new JDialog((JFrame)null, "Test JDialog", true);

      // Using rigid area just to give the dialog size, but you
      // could put any complex GUI in a JPanel in here
      dialog.getContentPane().add(Box.createRigidArea(new Dimension(400, 400)));
      dialog.pack();
      dialog.setLocationByPlatform(true);
      dialog.setVisible(true);
      System.exit(0); // to end Swing event thread
   }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            createAndShowGui();
         }
      });
   }
}

A downside is that you lose the minimize and restore buttons in the upper right corner of your window, but you shouldn't have these anyway since you have no associated icon with which to restore the GUI.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Thank you Hovercraft, it is helpfull and I will use it if I will not found any other method to do that. Actually I don't think it will be good to use JDialog in the place of JFrame. But your answer is helpfull. – afzalex Sep 08 '14 at 23:48
  • @afzalex: Regarding, `"Actually I don't think it will be good to use JDialog in the place of JFrame."` -- why do you think this is so? And as always, glad to be of service! – Hovercraft Full Of Eels Sep 08 '14 at 23:50
  • @afzalex: if you enjoy C coding, you could also use JNI or JNA to make OS calls to remove any icons from the taskbar. This solution would of course be OS-specific. – Hovercraft Full Of Eels Sep 09 '14 at 00:03
  • `+1` I don't know, but I will want to use JFrame (which is usual), I don't have found any code or any recommendation (like from oracle documentation) to directly create JDialog, instead of JFrame. I will be happy if I can achieve it using JFrame. – afzalex Sep 09 '14 at 00:14
  • @afzalex: not my down-vote on your question, but I still have to wonder why you prefer to use JFrame. What is your rationale for this? – Hovercraft Full Of Eels Sep 09 '14 at 00:26
  • @afzalex: thank you for the reply. Best of luck with your project! – Hovercraft Full Of Eels Sep 09 '14 at 00:41
  • I only use JDialogs for preference boxes, login boxes, etc. and as I said in previous comment. But now I will have to use JDialog now and I think there will not be any problem later using this. :) (mistakenly written JFrame intead of JDialog) – afzalex Sep 09 '14 at 00:58