This patch corrects the calculation of the cell width for VERTICAL
layoutOrientation in JLists and greatly improves performance of JList
painting by saving most updateLayoutState() calls from within paint().

2006-01-28  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicListUI.java
        (getCellBounds): Determine correct list width when having a
        layoutOrientation of VERTICAL.
        (maybeUpdateLayoutState): Don't consider the validation state of
        the list.

/Roman
Index: javax/swing/plaf/basic/BasicListUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v
retrieving revision 1.50
diff -u -r1.50 BasicListUI.java
--- javax/swing/plaf/basic/BasicListUI.java	10 Jan 2006 13:13:48 -0000	1.50
+++ javax/swing/plaf/basic/BasicListUI.java	28 Jan 2006 20:23:24 -0000
@@ -720,12 +720,19 @@
     int minIndex = Math.min(index1, index2);
     int maxIndex = Math.max(index1, index2);
     Point loc = indexToLocation(list, minIndex);
-    Rectangle bounds = new Rectangle(loc.x, loc.y, cellWidth,
+
+    // When the layoutOrientation is VERTICAL, then the width == the list
+    // width. Otherwise the cellWidth field is used.
+    int width = cellWidth;
+    if (l.getLayoutOrientation() == JList.VERTICAL)
+      width = l.getWidth();
+
+    Rectangle bounds = new Rectangle(loc.x, loc.y, width,
                                      getCellHeight(minIndex));
     for (int i = minIndex + 1; i <= maxIndex; i++)
       {
         Point hiLoc = indexToLocation(list, i);
-        Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,
+        Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, width,
                                            getCellHeight(i));
         bounds = bounds.union(hibounds);
       }
@@ -894,7 +901,7 @@
    */
   protected void maybeUpdateLayoutState()
   {
-    if (updateLayoutStateNeeded != 0 || !list.isValid())
+    if (updateLayoutStateNeeded != 0)
       {
         updateLayoutState();
         updateLayoutStateNeeded = 0;

Reply via email to