Created
September 20, 2015 13:54
-
-
Save smamran/0a33dfabb339590aab7e to your computer and use it in GitHub Desktop.
Exit Focused JFrame by Pressing Esc Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( | |
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); | |
getRootPane().getActionMap().put("Cancel", new AbstractAction() | |
{ | |
public void actionPerformed(ActionEvent e) | |
{ | |
System.exit(0); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment