[Patch][gui] javax.swing.JTable

Michael Koch konqueror@gmx.de
Tue Sep 28 01:15:00 GMT 2004


Hi lists,


I just applied the attached patch to java-gui-branch and GNU classpath
to fix javax.swing.JTable.setModel.


Michael


2004-09-27  Michael Koch  <konqueror@gmx.de>

	* javax/swing/JTable.java
	(setModel): Reimplemented.

-------------- next part --------------
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTable.java,v
retrieving revision 1.4.18.6
diff -u -r1.4.18.6 JTable.java
--- javax/swing/JTable.java	12 Sep 2004 20:27:43 -0000	1.4.18.6
+++ javax/swing/JTable.java	27 Sep 2004 13:24:11 -0000
@@ -1148,16 +1148,32 @@
    */ 
   public void setModel(TableModel m)
   {
+    // Throw exception is m is null.
     if (m == null)
       throw new IllegalArgumentException();
-    TableModel tmp = dataModel;
-    if (autoCreateColumnsFromModel)
-      createColumnsFromModel();
-    if (tmp != null)
-      tmp.removeTableModelListener(this);
+   
+    // Don't do anything if setting the current model again.
+    if (dataModel == m)
+      return;
+    
+    // Remove table as TableModelListener from old model.
+    if (dataModel != null)
+      dataModel.removeTableModelListener(this);
+    
     if (m != null)
-      m.addTableModelListener(this);
-    dataModel = m;
+      {
+	// Set property.
+        dataModel = m;
+
+	// Add table as TableModelListener to new model.
+	dataModel.addTableModelListener(this);
+
+	// Automatically create columns.
+	if (autoCreateColumnsFromModel)
+	  createColumnsFromModel();
+      }
+    
+    // Repaint table.
     revalidate();
     repaint();
   }


More information about the Java-patches mailing list