frame.addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(WindowEvent e) {
if (e.getNewState() == ICONIFIED) {
try {
tray.add(trayIcon);
frameLogin.setVisible(false);
} catch (AWTException ex) {
}
}
}
});
this will add my application in system tray but i want to add my application in system tray when user clicked on cross not in the case of minimize
As @mKorbel says,
WindowListener
+DefaultCloseOperation
works fine for me: