List of utility methods to do JDialog Escape Key
void | decorate(final JDialog d, boolean closeOnEscape) decorate center(d);
setIcon(d);
if (closeOnEscape) {
addEscapeListener(d);
|
void | enableCloseByEscape(final JDialog dialog) enable Close By Escape AbstractAction closeAction = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { dialog.setVisible(false); dialog.dispose(); }; KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escapeStroke, ... |
void | installEscapeCloseOperation(final JDialog dialog) Add a keyboard shortcut to allow ESC to close the dialog. JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); Action dispatchClosing = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }; ... |
void | installEscapeCloseOperation(final JDialog dialog) install Escape Close Operation Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(final ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }; JRootPane root = dialog.getRootPane(); ... |
void | installEscapeCloseOperation(final JDialog dialog) install Escape Close Operation Action dispatchClosing = new AbstractAction() { public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY); root.getActionMap().put(ESCAPE_KEY, dispatchClosing); ... |
void | installEscapeKey(final JDialog comp) install Escape Key KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Action escapeAction = new AbstractAction() { public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) { comp.setVisible(false); }; comp.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE"); comp.getRootPane().getActionMap().put("ESCAPE", escapeAction); ... |
void | registerEscapeKey(final JDialog dialog, ActionListener actionListener) register Escape Key dialog.getRootPane().registerKeyboardAction(actionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); |
void | setEscapeAction(JDialog dialog, Action action) Associate a custom action to be called when the Esc key is pressed. setEscapeAction(dialog.getRootPane(), action); |
void | setEscapeClosable(JDialog dialog) Make a dialog closeable by pressing the Esc key. setEscapeAction(dialog.getRootPane(), makeCloseAction(dialog)); |