Reputation: 1265
how i can stop JDialog to close to close when the Esc key is press. i want keep it as it is. i have already tried the dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); but this is not working on Esc key
Upvotes: 0
Views: 524
Reputation: 324118
I was not aware that the escape key would close a dialog automatically. At least it doesn't work using JDK7 on Windows 7.
If it does work on other Look and Feels, then I would guess that LAF is using Key Bindings.
You could try to use a dummy key binding:
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(escapeKeyStroke, "do nothing");
If that doesn't help then post your SSCCE that demonstrates the problem.
Upvotes: 2