changeset 5479:df88ad5d6621

RT-25059 ListView scroll bar thumb resizes wildly Reviewed-by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 22 Oct 2013 09:33:16 +0200
parents 544f4caaf4aa
children e971b9ac99d8
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java
diffstat 1 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Mon Oct 21 22:22:32 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Tue Oct 22 09:33:16 2013 +0200
@@ -881,10 +881,13 @@
             lastWidth = -1;
             lastHeight = -1;
         }
+
+        boolean recreatedOrRebuilt = needsRebuildCells || needsRecreateCells || sizeChanged;
        
         needsRecreateCells = false;
         needsReconfigureCells = false;
         needsRebuildCells = false;
+        sizeChanged = false;
         
         if (needsCellsLayout) {
             for (int i = 0, max = cells.size(); i < max; i++) {
@@ -1047,7 +1050,7 @@
         }
 
         updateViewport();
-        updateScrollBarsAndCells();  
+        updateScrollBarsAndCells(recreatedOrRebuilt);
 
         // Get the index of the "current" cell
         int currentIndex = computeCurrentIndex();
@@ -1097,7 +1100,7 @@
         }
 
         updateViewport(); 
-        updateScrollBarsAndCells();
+        updateScrollBarsAndCells(false);
 
         lastWidth = getWidth();
         lastHeight = getHeight();
@@ -1339,6 +1342,7 @@
     @Override protected void setWidth(double value) {
         if (value != lastWidth) {
             super.setWidth(value);
+            sizeChanged = true;
             setNeedsLayout(true);
             requestLayout();
         }
@@ -1347,12 +1351,13 @@
     @Override protected void setHeight(double value) {
         if (value != lastHeight) {
             super.setHeight(value);
+            sizeChanged = true;
             setNeedsLayout(true);
             requestLayout();
         }
     }
 
-    private void updateScrollBarsAndCells() {
+    private void updateScrollBarsAndCells(boolean recreate) {
         // Assign the hbar and vbar to the breadthBar and lengthBar so as
         // to make some subsequent calculations easier.
         final boolean isVertical = isVertical();
@@ -1468,29 +1473,30 @@
         if (lengthBar.isVisible()) {
             // determine how many cells there are on screen so that the scrollbar
             // thumb can be appropriately sized
-            int numCellsVisibleOnScreen = 0;
-            for (int i = 0, max = cells.size(); i < max; i++) {
-                T cell = cells.get(i);
-                if (cell != null && ! cell.isEmpty()) {
-                    sumCellLength += (isVertical ? cell.getHeight() : cell.getWidth());
-                    if (sumCellLength > flowLength) {
-                        break;
+            if (recreate) {
+                int numCellsVisibleOnScreen = 0;
+                for (int i = 0, max = cells.size(); i < max; i++) {
+                    T cell = cells.get(i);
+                    if (cell != null && ! cell.isEmpty()) {
+                        sumCellLength += (isVertical ? cell.getHeight() : cell.getWidth());
+                        if (sumCellLength > flowLength) {
+                            break;
+                        }
+
+                        numCellsVisibleOnScreen++;
                     }
+                }
 
-                    numCellsVisibleOnScreen++;
+                lengthBar.setMax(1);
+                if (numCellsVisibleOnScreen == 0 && cellCount == 1) {
+                    // special case to help resolve RT-17701 and the case where we have
+                    // only a single row and it is bigger than the viewport
+                    lengthBar.setVisibleAmount(flowLength / sumCellLength);
+                } else {
+                    lengthBar.setVisibleAmount(numCellsVisibleOnScreen / (float) cellCount);
                 }
             }
 
-            lengthBar.setMax(1);
-            if (numCellsVisibleOnScreen == 0 && cellCount == 1) {
-                // special case to help resolve RT-17701 and the case where we have
-                // only a single row and it is bigger than the viewport
-                lengthBar.setVisibleAmount(flowLength / sumCellLength);
-            } else {
-                lengthBar.setVisibleAmount(numCellsVisibleOnScreen / (float) cellCount);
-            }
-            
-
             // Fix for RT-11873. If this isn't here, we can have a situation where
             // the scrollbar scrolls endlessly. This is possible when the cell
             // count grows as the user hits the maximal position on the scrollbar
@@ -2169,7 +2175,7 @@
         cull();
 
         // Finally, update the scroll bars
-        updateScrollBarsAndCells();
+        updateScrollBarsAndCells(false);
         lastPosition = getPosition();
 
         // notify
@@ -2180,6 +2186,7 @@
     private boolean needsRecreateCells = false; // when cell factory changed
     private boolean needsRebuildCells = false; // when cell contents have changed
     private boolean needsCellsLayout = false;
+    private boolean sizeChanged = false;
     
     public void reconfigureCells() {
         needsReconfigureCells = true;