List of usage examples for javax.swing JDialog getDefaultCloseOperation
public int getDefaultCloseOperation()
From source file:org.apache.cayenne.modeler.util.CayenneController.java
/** * If this view or a parent view is a JDialog, makes it closeable on ESC hit. Dialog * "defaultCloseOperation" property is taken into account when processing ESC button * click.// w ww .ja v a2 s. com */ protected void makeCloseableOnEscape() { Window window = getWindow(); if (!(window instanceof JDialog)) { return; } final JDialog dialog = (JDialog) window; KeyStroke escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true); ActionListener closeAction = new ActionListener() { public void actionPerformed(ActionEvent e) { if (dialog.isVisible()) { switch (dialog.getDefaultCloseOperation()) { case JDialog.HIDE_ON_CLOSE: dialog.setVisible(false); break; case JDialog.DISPOSE_ON_CLOSE: dialog.setVisible(false); dialog.dispose(); break; case JDialog.DO_NOTHING_ON_CLOSE: default: break; } } } }; dialog.getRootPane().registerKeyboardAction(closeAction, escReleased, JComponent.WHEN_IN_FOCUSED_WINDOW); }