Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6382722

REGRESSION: Tabbing to JTable broken

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      In JRE 1.5.0_06 (but not 1.5.0_05 or _04) when the keyboard focus moves (because of a tab key press) onto a table for the first time, the initial cell does not get the keyboard focus (as it does in previous jre versions). A second tab selects the row, and puts the focus on the first cell.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the included program.

      When the program starts, the focus will be on the button "Tab Off Me". Press tab once to move to focus to the table from the button.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the first cell in the table to get the keyboard focus, such that F2 would put it into edit mode.
      ACTUAL -
      In 1.5.0_06 the focus is apparently lost (althoug another tab will put it clearly on the table). It works in 1.5.0_05

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JTable;
      import javax.swing.UIManager;
      import javax.swing.table.DefaultTableModel;

      public class TestApp
      {
          //~ Static fields/initializers -----------------------------------------------------------------

          public static final int TABLE_SIZE_SIZE = 10;

          //~ Constructors -------------------------------------------------------------------------------

          public TestApp()
          {
              super();
          }

          //~ Methods ------------------------------------------------------------------------------------

          public static void main(String[] args)
          {
              System.out.println("JRE: " + System.getProperty("java.vm.version"));

              try
              {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  System.exit(-1);
              }

              JFrame frame = new JFrame("Test Table App");
              setupFrame(frame);
              frame.setVisible(true);
          }

          private static void setupFrame(JFrame frame)
          {
              frame.addWindowListener(new WindowAdapter()
                  {
                      @Override
                      public void windowClosing(WindowEvent e)
                      {
                          System.exit(0);
                      }
                  });
              frame.setSize(200, 200);
              frame.getContentPane().setLayout(new BorderLayout());

              JButton button = new JButton("Tab Off Me");
              JTable table = getTable();

              frame.getContentPane().add(button, BorderLayout.NORTH);
              frame.getContentPane().add(table, BorderLayout.CENTER);
          }

          private static JTable getTable()
          {
              JTable table = new JTable();
              DefaultTableModel tableModel = (DefaultTableModel)table.getModel();
              
              tableModel.setColumnCount(TABLE_SIZE_SIZE);
              tableModel.setRowCount(TABLE_SIZE_SIZE);

              for (int i = 0; i < TABLE_SIZE_SIZE; ++i)
              {
                  for (int j = 0; j < TABLE_SIZE_SIZE; ++j)
                  {
                      table.setValueAt((2 * i) + (3 * j), i, j);
                  }
              }

              return table;
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Press tab again

      Release Regression From : 5.0u5
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

            shickeysunw Shannon Hickey (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: