【问题标题】:Hide Java application to System Tray将 Java 应用程序隐藏到系统托盘
【发布时间】:2016-09-03 13:01:46
【问题描述】:

我想从任务栏中隐藏我的 Java 应用程序,并使其仅在系统托盘中可见。这是一张图片,以防不清楚。

我尝试像this 一样实现它,图标确实出现在系统托盘中,但它仍在任务栏上显示应用程序。

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

}

我只需要找到如何从任务栏中隐藏应用程序。

【问题讨论】:

  • 相当确定你是否有一个窗口,它会显示在任务栏中;任务栏实际上只是一个窗口列表

标签: java hide taskbar system-tray


【解决方案1】:

这样做setVisible(false)然后任务栏中将没有任何内容

【讨论】:

    猜你喜欢
    • 2013-01-15
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2010-10-19
    • 2011-11-29
    相关资源
    最近更新 更多