posted 13 years ago
It's setExtendedState, with the state set to x | Frame.ICONIFIED where x is the current extended state. To restore, you then call setExtendendState with the state set to x & ~Frame.ICONIFIED with x again being the current extended state. By using this approach, the frame will go back to the previous state - maximized or not.
However, this will still show the application in the task bar. You will need to call setVisible(false) as well. The best way to handle this:
- minimize by clicking the icon in the frame's title bar: use a WindowListener that calls setVisible(false) in the windowIconified method.
- minimize from code: first use setExtendedState as I described above, then call setVisible(false).
- restoring from code: first call setVisible(true), then use setExtendedState as I described above.