DefaultTableModel.setColumnIdentifiers() Clears JTable Row Heights

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: client-libs
    • Cause Known
    • x86
    • windows_xp

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

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

      A DESCRIPTION OF THE PROBLEM :
      Calling DefaultTableModel.setColumnIdentifiers() results in the firing of a TableModelEvent. When JTable.tableChanged() processes this event, it sets rowModel = null, which clears all row height data. This effect does not seem consistent with an action that does not modify the table data, but only the table header.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JTable with some columns using the DefaultTableModel and add several rows of test data. Set the row heights to something other than the default (like 100) using JTable.setRowHeight(row, height). Call DefaultTableModel.setColumnIdentifiers(Object[]) and supply a number of identifiers equal to the number of columns.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Assuming that setting column identifiers is expected to result in a change of the displayed header values, the heights of the table rows should remain unchanged.
      ACTUAL -
      The row heights change to the default value (16).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.table.*;

      import java.awt.event.*;
      import java.awt.*;

      public class Test extends JFrame implements ActionListener {
      private DefaultTableModel model;

      public Test() {
      model = new DefaultTableModel(null, new Object[] {"FOO", "BAR"});
      JTable table = new JTable(model);

      model.addRow(new Object[] {"00", "01"});
      model.addRow(new Object[] {"10", "11"});
      model.addRow(new Object[] {"20", "21"});

      for (int row = 0; row < table.getRowCount(); row++) {
      table.setRowHeight(row, 100);
      }

      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

      JButton button = new JButton("Set Column Identifiers");
      button.addActionListener(this);
      getContentPane().add(button, BorderLayout.SOUTH);

      pack();
      }

      public void actionPerformed(ActionEvent e) {
      model.setColumnIdentifiers(new Object[] {"Check", "it out!"});
      }

      public static void main(String[] args) {
      java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new Test().setVisible(true);
                  }
              });
      }
      }

      ---------- END SOURCE ----------
      ###@###.### 2005-06-29 09:41:40 GMT

            Assignee:
            Unassigned
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: