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

JTable select highlights random cells if zero column width present

XMLWordPrintable

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

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

      A DESCRIPTION OF THE PROBLEM :
      JTable rows selection is not hightlighted properly, if we have a column with zero width. The problem appears only if the first or last column of the table has zero width.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case below. After the frame opens just try to select around different rows in the table and eventually scroll the table content a little.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The selected rows should have a different and consistent background color.
      ACTUAL -
      The cells that are colored as selected are not related to the real selection.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bugs;

      import java.awt.Dimension;
      import java.awt.Toolkit;

      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;

      public class TableWheel {

          public static void main(String[] args) {
              JFrame frame = new JFrame("Mustang Swing Bug");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(new JScrollPane(TableWheel.getJTable()));
              Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setBounds((screen.width-300)/2,(screen.height-200)/2,300,200);
              frame.setVisible(true);
          }
          
          public static JTable getJTable() {
              Object[][] data = {
                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1"},
                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1"},
                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1"},
                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1"},
                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}
                      };
              Object[] columns = {"Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8", "Col9", "Col10"};
              //int[] widths = {100, 0, 100, 100, 100, 100, 100, 100, 100, 100};
              int[] widths = {0, 100, 100, 100, 100, 100, 100, 100, 100, 100};
              
              JTable table = new JTable(data, columns);
              table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
              
              for (int i = 0; i < table.getColumnCount(); i++) {
                  table.getColumn(table.getColumnName(i)).setPreferredWidth(widths[i]);
                  table.getColumn(table.getColumnName(i)).setWidth(widths[i]);
                  if(widths[i] == 0) {
                      table.getColumn(table.getColumnName(i)).setMinWidth(0);
                      table.getColumn(table.getColumnName(i)).setMaxWidth(0);
                  } else {
                      table.getColumn(table.getColumnName(i)).setMinWidth(10);
                  }
              }
              
              return table;
          }

      }

      ---------- 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)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: