import java.awt.event.*;import javax.swing.*;public class EscapeDialog extends JDialog{ public static void main(String[]args) { new EscapeDialog(); } private JTextField input = null; public EscapeDialog() { setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); initTextField(); pack(); setLocationRelativeTo(null); setVisible(true); } private void initTextField() { input = new JTextField(10); getContentPane().add(input); } protected JRootPane createRootPane() { ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }; JRootPane rootPane = new JRootPane(); //Escape schließt den Dialog egal wer Focus hat! KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); rootPane.registerKeyboardAction(exitListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; } }