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

JTable behaves differently in an JFrame directly vs in a JInternalFrame

    XMLWordPrintable

    Details

    • Subcomponent:
    • Understanding:
      Fix Understood
    • Introduced In Build:
      b46
    • Introduced In Version:
      6
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      If I have a JTable, and I set all the columns to use the DefaultCellEditor with the clickCountToStart set to 1 (it defaults to 2), the table works fine if placed on a panel directly within a JFrame. But if it is placed within a JInternalFrame, the focus is all messed up.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the test case
      2. Click on the JTextField under Label "Field1".
      3. Click inside a cell in the JTable below the JTextField.
      4. Note that even DefaultCellEditor.setClickCountToStart(1) is used.
      5. Comment line 70 & uncomment line 71 in the test case
      6. Repeat 2 & 3 to observe the difference.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.util.Enumeration;
      import javax.swing.BoxLayout;
      import javax.swing.DefaultCellEditor;
      import javax.swing.JDesktopPane;
      import javax.swing.JFrame;
      import javax.swing.JInternalFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.JTextField;
      import javax.swing.table.TableColumn;
      import javax.swing.table.TableColumnModel;
       
      public class TableTest extends JFrame
      {

      public TableTest()
      {
      addWindowListener(new java.awt.event.WindowAdapter()
      {
      public void windowClosing(java.awt.event.WindowEvent evt)
      {
      System.exit(0);
      }
      });

      JPanel panel = new JPanel();
      panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

      String[] columnNames = {"First Name", "Last Name","Sport","# of Years","Vegetarian"};
      Object[][] data= new Object[3][5];
      JTable table = new JTable(data, columnNames);
      table.setSurrendersFocusOnKeystroke(true);
      table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

      DefaultCellEditor editor = new DefaultCellEditor(new JTextField());

      // ************ change to 2 to make it work smoothly
      editor.setClickCountToStart(1);
      TableColumnModel tcm = table.getColumnModel();
      Enumeration e = tcm.getColumns();
      TableColumn col = null;
      while( e.hasMoreElements() )
      {
      col = (TableColumn) e.nextElement();
      col.setCellEditor(editor);
      }

      JScrollPane jScrollPane = new JScrollPane();
      jScrollPane.setViewportView(table);

      panel.add(new JLabel("Field 1"));
      panel.add(new JTextField(15));
      panel.add(jScrollPane);

      // ************ comment out one or the other of these to see error
      initInteralFrame(panel);
      //initNoInteralFrame(panel);

      Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
      setSize(new Dimension(800, 600));
      setLocation((screenSize.width-800)/2,(screenSize.height-600)/2);
      }

      private void initInteralFrame(JPanel panel)
      {
      JInternalFrame jif = new JInternalFrame();
      JDesktopPane desktop = new JDesktopPane();
      jif.setVisible(true);
      desktop.add(jif);
      setContentPane(desktop);
      jif.add(panel);
      jif.pack();
      }

      private void initNoInteralFrame(JPanel panel)
      {
      getContentPane().add(panel);
      }

      /**
      * @param args the command line arguments
      */
      public static void main(String args[])
      {
      new TableTest().setVisible(true);
      }

      }

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ryeung Roger Yeung (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: