This rewrites the rowAtPoint method in JTable, replacing loop by division. The table may have 20000 rows or about (only part visible in the scroll pane). Hence the loop delay may already be significant.

2006-01-19  Audrius Meskauskas  <[EMAIL PROTECTED]>

* javax/swing/JTable.java (rowAtPoint): Rewritten.

Index: JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.67
diff -u -r1.67 JTable.java
--- JTable.java	19 Jan 2006 21:46:25 -0000	1.67
+++ JTable.java	19 Jan 2006 22:11:48 -0000
@@ -1940,12 +1940,13 @@
   }
 
   /**
-   * Returns index of the row that contains specified point or 
-   * -1 if this table doesn't contain this point.
-   *
-   * @param point point to identify the row
-   * @return index of the row that contains specified point or 
-   * -1 if this table doesn't contain this point.
+   * Returns index of the row that contains specified point or -1 if this table
+   * doesn't contain this point.
+   * 
+   * @param point
+   *          point to identify the row
+   * @return index of the row that contains specified point or -1 if this table
+   *         doesn't contain this point.
    */
   public int rowAtPoint(Point point)
   {
@@ -1955,14 +1956,14 @@
         int height = getRowHeight() + getRowMargin();
         int y = point.y;
 
-        for (int i = 0; i < nrows; ++i)
-          {
-            if (0 <= y && y < height)
-              return i;
-            y -= height;
-          }
+        int r = y / height;
+        if (r < 0 || r > nrows)
+          return -1;
+        else
+          return r;
       }
-    return -1;
+    else
+      return -1;
   }
 
   /** 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to