This restores JTable's scrolling behaviour so that partially exposed rows of a JTable are completely exposed by scrolling. This is actually slightly better than the previous implementation, as this couldn't really have worked with variable height rows (for that case we now return the default unit of one row height).

2006-08-14  Roman Kennke  <[EMAIL PROTECTED]>

        PR 28720
        * javax/swing/JTable
        (getScrollableUnitIncrement): Expose partially exposed
        row in scrolling direction.

/Roman
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.120
diff -u -1 -2 -r1.120 JTable.java
--- javax/swing/JTable.java	14 Aug 2006 14:09:07 -0000	1.120
+++ javax/swing/JTable.java	14 Aug 2006 14:27:18 -0000
@@ -3357,25 +3357,47 @@
    *          events were generated, and hence it is better to scroll the longer
    *          distance.
    *          
    * @author Roman Kennke ([EMAIL PROTECTED])
    */
   public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
                                         int direction)
   {
     int unit;
     if (orientation == SwingConstants.HORIZONTAL)
       unit = 100;
     else
-      unit = getRowHeight();
+      {
+        unit = getRowHeight();
+        // The following adjustment doesn't work for variable height rows.
+        // It fully exposes partially visible rows in the scrolling direction.
+        if (rowHeights == null)
+          {
+            if (direction > 0)
+              {
+                // Scroll down.
+                // How much pixles are exposed from the last item?
+                int exposed = (visibleRect.y + visibleRect.height) % unit;
+                if (exposed > 0 && exposed < unit - 1)
+                  unit = unit - exposed - 1;
+              }
+            else
+              {
+                // Scroll up.
+                int exposed = visibleRect.y % unit;
+                if (exposed > 0 && exposed < unit)
+                  unit = exposed;
+              }
+          }
+      }
     return unit;
   }
 
   /**
    * Get the cell editor, suitable for editing the given cell. The default
    * method requests the editor from the column model. If the column model does
    * not provide the editor, the call is forwarded to the
    * [EMAIL PROTECTED] #getDefaultEditor(Class)} with the parameter, obtained from
    * [EMAIL PROTECTED] TableModel#getColumnClass(int)}.
    * 
    * @param row the cell row
    * @param column the cell column

Reply via email to