'Hide Java application to System Tray

I want to hide my Java application from the taskbar and for it to be visible only at the system tray. Here is a picture in case this is unclear.

image

I tried to implement it like this and the icon did appear in the system tray but it is still showing the application on the taskbar.

Here is part of the Frame class

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

}

I just need to find how to hide the application from the taskbar.



Solution 1:[1]

do this setVisible(false) then there will be nothing in the taskbar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 WarrenFaith