Forums Register Login

How to close the Frame by clicking the Esc Button?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]

 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4334 times.
Similar Threads
Close Dialog Box(Urgent!)
How to close a frame by clicking Esc Button?
getting KeyPressed for JDialog? example?
How to frozen a mother window after opening a child window
No javascript for child windows.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:28:12.