This patch fixes the recently reported NPE when starting jMemorize. The reason is, the jMemorize overrides the columnMarginChanged that is called from the JTable super constructor when the user derived instance is still not capable to respond (not yet constructed). The event is fired when setting the initial table row margin. It can be suppressed by setting the margin value before setting the table model value to the table. The Swing Demo table seems still working ok.

2006-03-30  Audrius Meskauskas  <[EMAIL PROTECTED]>

   * javax.swing.JTable (constructor): Initialize column
   model column margin and table row margin before setting the
   table column mode.
   table model. (initialiseLocalVars): Do not call setIntercellSpacing.
Index: JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.90
diff -u -r1.90 JTable.java
--- JTable.java	21 Mar 2006 18:42:30 -0000	1.90
+++ JTable.java	30 Mar 2006 20:33:25 -0000
@@ -1651,13 +1651,22 @@
   public JTable (TableModel dm, TableColumnModel cm, ListSelectionModel sm)
   {
     boolean autoCreate = false;
+    TableColumnModel columnModel;
     if (cm != null)
-        setColumnModel(cm);
+        columnModel = cm;
     else 
       {
-        setColumnModel(createDefaultColumnModel());
+        columnModel = createDefaultColumnModel();
         autoCreate = true;
-      }        
+      }
+    
+    // Initialise the intercelar spacing before setting the column model to
+    // avoid firing unnecessary events.
+    // The initial incellar spacing is new Dimenstion(1,1). 
+    rowMargin = 1;
+    columnModel.setColumnMargin(1);
+    setColumnModel(columnModel);
+    
     setSelectionModel(sm == null ? createDefaultSelectionModel() : sm);
     setModel(dm == null ? createDefaultDataModel() : dm);
     setAutoCreateColumnsFromModel(autoCreate);
@@ -1717,7 +1726,6 @@
     this.showVerticalLines = true;
     this.editingColumn = -1;
     this.editingRow = -1;
-    setIntercellSpacing(new Dimension(1,1));
   }
   
   /**

Reply via email to