Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

easy question

How do I enable a JPanel or JFrame to close (or program to exit) if a user presses the ESCAPE button?
0
rich420
Asked:
rich420
1 Solution
 
TimYatesCommented:
final String CANCEL_DIALOG = "cancel-dialog";
panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_DIALOG);
panel.getActionMap().put(CANCEL_DIALOG, new AbstractAction()
         {  
           public void actionPerformed(ActionEvent event)
           {    
             // close dialog here  
           }
         } );
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now