Java: minimize Application window

The following method could be used to minimize application window, if java.awt.Frame or its subclass is used:

public void setState(int state)
Parameters:
state – Frame.ICONIFIED if this frame is in iconic state;
Frame.NORMAL if this frame is in normal state.

Example:

// Close window on ESC
// use it in the constructor of the window, extending JFrame
//
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setState(Frame.ICONIFIED);
}
} , stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.