• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to close the Frame by clicking the Esc Button?  RSS feed

 
Sathiq Ali
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have one problem in Java Swings. I have a one main window which is a frame and that contains three buttons, If I clicked one Button, It has to open a new Jframe window. The other Two buttons are such as Save and Cancel. The new Window also contains two buttons such as Save and Cancel .Now if I click the Esc button from the key Board, It has to close only the new window. But Now It is closing both the windows. how to make difference b/w two windows while clicking ESc button?
Advance thanks
 
Stephan Oudmaijer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Action escapeAction = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
// Close your window here
}
};

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);
[ January 31, 2006: Message edited by: Stephan Oudmaijer ]
 
Sathiq Ali
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply. It is working fine.

Originally posted by Stephan Oudmaijer:
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Action escapeAction = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
// Close your window here
}
};

getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);

[ January 31, 2006: Message edited by: Stephan Oudmaijer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!