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

Wrong JTable highlite selection when a JTable has a column width of 0

XMLWordPrintable

    • b86
    • 6
    • b94
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      1.6.0-rc-b87

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP Professional Version 2002 SP2 with all updates applied.

      A DESCRIPTION OF THE PROBLEM :
      When a JTable has a column with a width of 0 clicking on one row isn't highliting the row itself but some of the columns instead.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Create a JTable with a column that has a JTable header set to 0 using table.getTableHeader().getColumnModel().getColumn(col).setMaxWidth(0);
      table.getTableHeader().getColumnModel().getColumn(col.setPreferredWidth(0);
      2. Set the size of the column to the minimum size using the GUI.
      3. Click on any row you will see that not all the row is being highlited

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expected result when clicking on a row in a JTable is to highlite the whole row.
      ACTUAL -
      A highlite of some of the columns.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.SwingUtilities;
      import javax.swing.table.DefaultTableModel;

      /*
       * Created on 19-Jun-06
       *
       * Copyright (c) Carl Antaki. All rights reserved
       *
       */

      public class JTableHighliteBug extends JPanel{
          JTable table;
          DefaultTableModel model;
          String[] col = {"One","Two","Hidden"};
          public JTableHighliteBug(){
              setLayout(new BorderLayout());
              model = new DefaultTableModel();
              table = new JTable(model);
              model.setColumnIdentifiers(col);
              Object[] obj= new Object[3];
              obj[0]="1";
              obj[1]="2";
              obj[2]="3";
              model.addRow(obj);
              model.addRow(obj);

              table.getTableHeader().getColumnModel().getColumn(2).setMinWidth(0);
              table.getTableHeader().getColumnModel().getColumn(2).setPreferredWidth(0);
              add(new JScrollPane(table),BorderLayout.CENTER);
          }

          public static void main(String[] args){
              SwingUtilities.invokeLater(new Runnable(){
                  public void run(){
                      createAndShowGUI();
                  }
              });
          }


          public static void createAndShowGUI(){
              JFrame frame = new JFrame("JTable Highlite Bug");
              frame.setContentPane(new JTableHighliteBug());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }
      }

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

      Release Regression From : 5.0u7
      The above release value was the last known release where this
      bug was not reproducible. 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: