Showing posts with label JFrame. Show all posts
Showing posts with label JFrame. Show all posts

2008-06-04

How to minimize and restore Java Swing JFrame

1. Minimize -> use this method frame.setState ( Frame.ICONIFIED );
2. Restore -> use this method frame.setState ( Frame.NORMAL );

frame is instance of JFrame

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");