This fixes bug #23203 where JList was returning -1 for
getLastVisibleIndex if the window was too large and there was therefore
extra "white space" at the bottom.  Patch attached.

2005-08-17  Anthony Balkissoon  <[EMAIL PROTECTED]>

        * javax/swing/JList.java:
        (indexToLocation): Implemented.
        (getLastVisibleIndex): If the last index in the list is showing and
        there is extra room at the bottom, return the last index, not -1.

-Tony
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.29
diff -u -r1.29 JList.java
--- javax/swing/JList.java	4 Aug 2005 14:56:05 -0000	1.29
+++ javax/swing/JList.java	17 Aug 2005 18:38:10 -0000
@@ -596,8 +596,7 @@
    * @return location of the cell located at the specified index in the list.
    */
    public Point indexToLocation(int index){
-   	//FIXME: Need to implement.
-	return null;
+     return getCellBounds(index, index).getLocation();
    }
 
   /**
@@ -605,7 +604,7 @@
    * [EMAIL PROTECTED] #visibleRect} property, depending on the [EMAIL PROTECTED]
    * #componentOrientation} property.
    *
-   * @return The index of the first visible list cell, or <code>-1</code>
+   * @return The index of the last visible list cell, or <code>-1</code>
    * if none is visible.
    */
   public int getLastVisibleIndex()
@@ -615,7 +614,10 @@
     r.translate(0, (int) r.getHeight() - 1);
     if (or == ComponentOrientation.LEFT_TO_RIGHT)
       r.translate((int) r.getWidth() - 1, 0);
-    return getUI().locationToIndex(this, r.getLocation());      
+    if (getUI().locationToIndex(this, r.getLocation()) == -1
+        && indexToLocation(getModel().getSize() - 1).y < r.y)
+      return getModel().getSize() - 1;
+    return getUI().locationToIndex(this, r.getLocation());
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to