Only one of the four JTable column resizing modes requires to repaint the whole table when resizing, and this mode is not the default one. Other modes only require to repaint the column being resized and columns right from it. This patch calculates the left boundary of the changed region, reducing the repaint area (it should be about two times smaller in average).

2006-05-22  Audrius Meskauskas  <[EMAIL PROTECTED]>

   * javax/swing/JTable.java (doLayout): In the column
   resize mode, only repaing the changed part of the table.
   (getLeftResizingBoundary): New method.
Index: JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.105
diff -u -r1.105 JTable.java
--- JTable.java	16 May 2006 19:27:37 -0000	1.105
+++ JTable.java	22 May 2006 10:09:29 -0000
@@ -3313,7 +3313,7 @@
   public void doLayout()
   {
     TableColumn resizingColumn = null;
-
+    
     int ncols = getColumnCount();
     if (ncols < 1)
       return;
@@ -3339,7 +3339,7 @@
       {
         TableColumn col;
         TableColumn [] cols;
-
+        
         switch (getAutoResizeMode())
           {
           case AUTO_RESIZE_LAST_COLUMN:
@@ -3401,21 +3401,49 @@
         TableColumn [] cols = new TableColumn[ncols];
         for (int i = 0; i < ncols; ++i)
           cols[i] = columnModel.getColumn(i);
-        distributeSpill(cols, spill);        
+        distributeSpill(cols, spill);
+        
+        repaint();
+        if (tableHeader != null)
+          tableHeader.repaint();
       }
     
     if (editorComp!=null)
       moveToCellBeingEdited(editorComp);
     
-    // Repaint fixes the invalid view after the first keystroke if the cell
-    // editing is started immediately after the program start or cell
-    // resizing. 
-    repaint();
-    if (tableHeader!=null)
-      tableHeader.repaint();
+    int leftBoundary = getLeftResizingBoundary();
+    int width = getWidth() - leftBoundary;
+    repaint(leftBoundary, 0, width, getHeight());
+    if (tableHeader != null)
+      tableHeader.repaint(leftBoundary, 0, width, tableHeader.getHeight());
   }
   
   /**
+   * Get the left boundary of the rectangle which changes during the column
+   * resizing.
+   */
+  int getLeftResizingBoundary()
+  {
+    if (tableHeader == null || getAutoResizeMode() == AUTO_RESIZE_ALL_COLUMNS)
+      return 0;
+    else
+      {
+        TableColumn resizingColumn = tableHeader.getResizingColumn();
+        if (resizingColumn == null)
+          return 0;
+
+        int rc = convertColumnIndexToView(resizingColumn.getModelIndex());
+        int p = 0;
+
+        for (int i = 0; i < rc; i++)
+          p += columnModel.getColumn(i).getWidth();
+        
+        return p;
+      }
+  }
+  
+  
+  /**
    * @deprecated Replaced by <code>doLayout()</code>
    */
   public void sizeColumnsToFit(boolean lastColumnOnly)

Reply via email to