簡體   English   中英

將 Java 應用程序隱藏到系統托盤

[英]Hide Java application to System Tray

我想從任務欄中隱藏我的 Java 應用程序,並使其僅在系統托盤中可見。 這是一張圖片,以防不清楚。

圖片

我試圖像這樣實現它並且圖標確實出現在系統托盤中但它仍在任務欄上顯示應用程序。

這是 Frame 類的一部分

public class Widget extends JFrame {
private static final long serialVersionUID = -197136854089859547L;
private JPanel mainPanel;
private WidgetProperties properties;
private Makedir mkdir;
private ArrayList<Item> items;
private Image icon;
private TrayIcon trayIcon;
private SystemTray tray;

public Widget() {
    super("");
    this.setTray();
    this.setUndecorated(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void setTray() {
    tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem show = new MenuItem("Show");
    MenuItem exit = new MenuItem("Exit");
    show.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            setState(Frame.NORMAL);
        }
    });
    exit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            close();
        }
    });
    menu.add(show);
    menu.addSeparator();
    menu.add(exit);
    trayIcon = new TrayIcon(icon, "EasyStart", menu);
    trayIcon.setImageAutoSize(true);
    try

    {
        tray.add(trayIcon);

    } catch (AWTException e) {
        e.printStackTrace();
    }
}

public void setup() {
    this.resize();
    this.setVisible(true);
}

public void resize() {
    this.setResizable(true);
    this.setShape(properties.getShape());
    this.setSize(properties.getSize());
    this.setResizable(false);
}

public void close() {
    System.exit(0);
}

}

我只需要找到如何從任務欄隱藏應用程序。

執行此setVisible(false)然后任務欄中將沒有任何內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM