简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM