This patch fixes an off-by-one-pixel problem in getFirstVisibleIndex and
getLastVisibleIndex.

I discovered this problem running the simple test case at the bottom of
this email and using the PAGE DOWN key.  Without this patch, 1 pixel of
a list item is showing at the bottom and thus page down does nothing
more than the down arrow key.

Patch attached.

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

* javax/swing/JList.java:
(getFirstVisibleIndex): Translate visible rectangle by one less pixel.
(getLastVisibleIndex): Likewise.


===TEST CASE ===
import java.awt.*;
import javax.swing.*;
import java.io.*;

class Test
{
  public static void main(String[] args) throws IOException
  {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] items = 
                     {
                       "Item1", "Item2", "Item3", "Item4", "Item5",
"Item6",
                       "Item7", "Item8", "Item9", "Item10", "Item11",
"Item12", "Item13",
                       "Item14", "Item15", "Item16", "Item17", "Item18"
                     };
    JList list = new JList(items);
    list.setPreferredSize(new Dimension(150, 150));

    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().setView(list);

    f.getContentPane().add(scroller);
    f.setSize(100, 200);

    f.show();
  }
}

-Tony
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.28
diff -u -r1.28 JList.java
--- javax/swing/JList.java	2 Jul 2005 20:32:47 -0000	1.28
+++ javax/swing/JList.java	2 Aug 2005 20:17:51 -0000
@@ -574,7 +574,7 @@
     ComponentOrientation or = getComponentOrientation();
     Rectangle r = getVisibleRect();
     if (or == ComponentOrientation.RIGHT_TO_LEFT)
-      r.translate((int) r.getWidth(), 0);
+      r.translate((int) r.getWidth() - 1, 0);
     return getUI().locationToIndex(this, r.getLocation());      
   }
 
@@ -612,9 +612,9 @@
   {
     ComponentOrientation or = getComponentOrientation();
     Rectangle r = getVisibleRect();
-    r.translate(0, (int) r.getHeight());
+    r.translate(0, (int) r.getHeight() - 1);
     if (or == ComponentOrientation.LEFT_TO_RIGHT)
-      r.translate((int) r.getWidth(), 0);
+      r.translate((int) r.getWidth() - 1, 0);
     return getUI().locationToIndex(this, r.getLocation());      
   }
 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to