classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI:Rewriting JTable.rowAtPoint


From: Audrius Meskauskas
Subject: [cp-patches] FYI:Rewriting JTable.rowAtPoint
Date: Thu, 19 Jan 2006 23:15:55 +0100
User-agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929)

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  <address@hidden>

* 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;
   }
 
   /** 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]