user2889419
user2889419

Reputation:

How to hide a swing form icon from taskbar?

Let say we have JFrame, once I set the visibility as true, the app icon is appeared(just as other apps) in task manager.
Question: is it possible to remove this icon(and the text) from the task manager?
thanks in advance.

Upvotes: 3

Views: 1365

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Create and display a JDialog, not a JFrame, and usually an icon will not be added to the task manager.

Run this program several times to test this for yourself:

import java.awt.Dimension;
import java.awt.Window;

import javax.swing.*;

public class Foo {
   public static void main(String[] args) {
      JPanel panel = new JPanel(new BorderLayout(5, 5));
      panel.add(Box.createRigidArea(new Dimension(400, 300)));

      Window window = null;
      if (Math.random() < 0.5) {
         window = new JDialog();
         ((JDialog) window).setTitle("Dialog");
      } else {
         window = new JFrame();
         ((JFrame)window).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         ((JFrame)window).setTitle("Frame");
      }     

      window.add(panel);
      window.pack();
      window.setLocationRelativeTo(null);
      window.setVisible(true);
   }
}

Upvotes: 3

Related Questions