将Java应用程序隐藏到系统托盘

将Java应用程序隐藏到系统托盘,java,hide,taskbar,system-tray,Java,Hide,Taskbar,System Tray,我想在任务栏中隐藏Java应用程序,使其仅在系统托盘中可见。这是一张图片,以防不清楚 我尝试像这样实现它,图标确实出现在系统托盘中,但它仍然在任务栏上显示应用程序 这是Frame类的一部分 public class Widget extends JFrame { private static final long serialVersionUID = -197136854089859547L; private JPanel mainPanel; private WidgetProperties

我想在任务栏中隐藏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);
}
公共类小部件扩展JFrame{
私有静态最终长serialVersionUID=-197136854089859547L;
私人JPanel主面板;
私人物业;
私有Makedir mkdir;
私有ArrayList项;
私人图像图标;
私人运输公司;
专用系统托盘;
公共小部件(){
超级(“”);
这个.setTray();
此项。未装饰的设置(正确);
此.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
公共无效设置盘(){
托盘=SystemTray.getSystemTray();
PopupMenu=新建PopupMenu();
菜单项显示=新菜单项(“显示”);
MenuItem exit=新MenuItem(“退出”);
show.addActionListener(新建ActionListener()){
@凌驾
已执行的公共无效操作(操作事件arg0){
设置状态(帧正常);
}
});
exit.addActionListener(新ActionListener(){
@凌驾
已执行的公共无效操作(操作事件arg0){
close();
}
});
菜单。添加(显示);
menu.addSeparator();
菜单。添加(退出);
trayIcon=新trayIcon(图标“EasyStart”,菜单);
trayIcon.setImageAutoSize(真);
尝试
{
托盘。添加(trayIcon);
}捕获(awtexe){
e、 printStackTrace();
}
}
公共作废设置(){
这是resize();
此.setVisible(true);
}
public void resize(){
此参数为.setresizeable(true);
this.setShape(properties.getShape());
this.setSize(properties.getSize());
此参数为.setresizeable(false);
}
公众假期结束(){
系统出口(0);
}
}


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

这样做
setVisible(false)
任务栏中将不会有任何内容

这样做
setVisible(false)
那么任务栏中将不会有任何内容

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