JDK-6236783 : JTable constructor calls columnSelectionChanged()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2005-03-07
  • Updated: 2011-02-16
  • Resolved: 2005-08-03
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux aehlaptop.akc.org 2.6.6-1.435.2.3 #1 Thu Jul 1 08:25:29 EDT 2004 i686 i686 i386 GNU/Linux

fails on ms-win too


A DESCRIPTION OF THE PROBLEM :
durring construction, the column selection seems to be getting set to the first (zeroth) column if and only if I override createDefaultDataModel() to create a model with > 0 columns.

This wasn't the case on 1.4.  I.e. columnSelectionChanged() didn't get called by the constructor.

The column selection should default to -1 (i.e. no column selected)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the source code as indicated.  on 1.4 it generates no output (good). on 1.5 it generates output (bad).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
(no output - createDefaultDataModel() is not invoked)
ACTUAL -
(createDefaultDataModel() IS invoked)

  evt = javax.swing.event.ListSelectionEvent[ source=javax.swing.DefaultListSelectionModel 4072869 ={} firstIndex= 0 lastIndex= 0 isAdjusting= false ]
  header is null: true


ERROR MESSAGES/STACK TRACES THAT OCCUR :
none...well, of course, you'll get a NullPointerException if you try to call getTableHeader.repaint() or such!

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Trash
{
   public static void main( String[] args )
   {
       javax.swing.JTable tab = new javax.swing.JTable() {

               protected javax.swing.table.TableModel createDefaultDataModel()
               {
                   return new javax.swing.table.AbstractTableModel() {
                           public Object getValueAt( int x, int y ) { return x + ", " + y; }
                           public int getRowCount() { return 0; }
                           public int getColumnCount() { return 1; }
                       };
               }

               public void columnSelectionChanged( javax.swing.event.ListSelectionEvent evt )
               {
                   System.out.println( "evt = " + evt );
                   System.out.println( "header is null: " + ( getTableHeader() == null ) );

               }
           };

   }
}
---------- END SOURCE ----------
###@###.### 2005-03-07 11:04:51 GMT

Comments
EVALUATION This has the same root cause as 4976239. Closing as a duplicate.
03-08-2005