import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class JTableEscapeKeyBug extends JDialog {

   public static void main(String[] args) {
      new JTableEscapeKeyBug();
   }
   public JTableEscapeKeyBug() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }}
      );

      JButton b = new JButton("Hello");
      Object[][] data = {
         {"one"},
         {"two"},
         {"three"}
      };
      String[] hdr = {"Header"};
      JTable table = new JTable(data, hdr);
      table.setBorder(BorderFactory.createLoweredBevelBorder());
      JTextField tf = new JTextField();
      tf.setText("some text");

      getContentPane().setLayout(new BorderLayout(10, 10));
      getContentPane().add(b, BorderLayout.NORTH);
      getContentPane().add(table);
      getContentPane().add(tf, BorderLayout.SOUTH);

      pack();
      setVisible(true);
   }
   protected JRootPane createRootPane() {

      // Create an actionListener that is used to close the
      // dialog in response to the Escape key being hit
      ActionListener actionListener = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            System.exit(0);
         }
      };
      
      JRootPane rootPane = new JRootPane();

      rootPane.registerKeyboardAction(
         actionListener, 
         KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
         JComponent.WHEN_IN_FOCUSED_WINDOW
      );
      return rootPane;
   }
}
