1. Minimize -> use this method frame.setState ( Frame.ICONIFIED );
2. Restore -> use this method frame.setState ( Frame.NORMAL );
frame is instance of JFrame
Showing posts with label JFrame. Show all posts
Showing posts with label JFrame. Show all posts
2008-05-20
Add KeyListener on Java Swing JFrame
Use a code like this
AbstractAction act = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
//Action that you want to do.
}
};
getRootPane().getActionMap().put("nameThatYouWant", act);
InputMap im = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
// KeyEvent.VK_F10 or any key that you want.
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "nameThatYouWant");
AbstractAction act = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
//Action that you want to do.
}
};
getRootPane().getActionMap().put("nameThatYouWant", act);
InputMap im = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
// KeyEvent.VK_F10 or any key that you want.
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "nameThatYouWant");
Subscribe to:
Posts (Atom)