I'm trying to implement a "iconify on quit" behavior in my Java JFrame app, like most native macOS apps have, but I'm quite stumped.
I've tried doing
Window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent Event) {
System.out.println("Closed on macOS, iconifiying");
Window.setExtendedState(Frame.ICONIFIED);
}
});
and closing the window on quit with (as well as adding a window listener that calls setVisible(false))
Window.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
The former didn't work because it looks like it's minimized and creates 2 separate icons. The latter didn't because I couldn't find a way to detect when the dock icon is clicked to unhide the window. I'd prefer this method if I could figure out how to do so. Does anybody know how to?