Skip to content

Instantly share code, notes, and snippets.

@smamran
Created September 20, 2015 13:54
Show Gist options
  • Save smamran/0a33dfabb339590aab7e to your computer and use it in GitHub Desktop.
Save smamran/0a33dfabb339590aab7e to your computer and use it in GitHub Desktop.
Exit Focused JFrame by Pressing Esc Key
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