You can close the attribute dialog with the ESC key.

This commit is contained in:
hneemann 2017-03-04 16:50:46 +01:00
parent c2fd3c65b5
commit ed51e971fa

View File

@ -83,27 +83,23 @@ public class AttributeDialog extends JDialog {
} }
}); });
JButton cancelButton = new JButton(new AbstractAction(Lang.get("cancel")) { final AbstractAction cancel = new AbstractAction(Lang.get("cancel")) {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
dispose(); dispose();
} }
}); };
buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonPanel.add(cancelButton); buttonPanel.add(new JButton(cancel));
buttonPanel.add(okButton); buttonPanel.add(okButton);
getContentPane().add(buttonPanel, BorderLayout.SOUTH); getContentPane().add(buttonPanel, BorderLayout.SOUTH);
getRootPane().setDefaultButton(okButton); getRootPane().setDefaultButton(okButton);
getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESC_ACTION_KEY); getRootPane().registerKeyboardAction(cancel,
getRootPane().getActionMap().put(ESC_ACTION_KEY, new AbstractAction() { KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
@Override JComponent.WHEN_IN_FOCUSED_WINDOW);
public void actionPerformed(ActionEvent actionEvent) {
dispose();
}
});
} }
/** /**