changeset 205:4499bb1a2e44

RT-18530: [ComboBox] Element adding leads to width increasing.
author jgiles
date Thu, 29 Dec 2011 16:47:13 +1000
parents 05a39a4e6788
children 87227803da34
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Dec 29 16:33:33 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Dec 29 16:47:13 2011 +1000
@@ -219,7 +219,7 @@
                         skin.updateCellCount();
                         itemCountDirty = false;
                     }
-                    pw = skin.getVirtualFlowPreferredWidth(height) + 10;
+                    pw = skin.getVirtualFlowPreferredWidth(-1) + 10;
                 } else {
                     pw = Math.max(100, comboBox.getWidth());
                 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Thu Dec 29 16:33:33 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Thu Dec 29 16:47:13 2011 +1000
@@ -1797,15 +1797,22 @@
 
     private static final double GOLDEN_RATIO_MULTIPLIER = 0.618033987;
 
-    private double getPrefBreadth() {
+    private double getPrefBreadth(double oppDimension) {
         double max = 0.0;
         int rows = Math.min(10, getCellCount());
         for (int i = 0; i < rows; i++) {
             max = Math.max(max, getCellBreadth(i));
         }
 
-        double prefLength = getPrefLength();
-        max = Math.max(max, prefLength * GOLDEN_RATIO_MULTIPLIER);
+        // This primarily exists for the case where we do not want the breadth
+        // to grow to ensure a golden ratio between width and height (for example,
+        // when a ListView is used in a ComboBox - the width should not grow
+        // just because items are being added to the ListView)
+        if (oppDimension > -1) {
+            double prefLength = getPrefLength();
+            max = Math.max(max, prefLength * GOLDEN_RATIO_MULTIPLIER);
+        }
+        
         return max;
     }
 
@@ -1819,12 +1826,12 @@
     }
 
     @Override protected double computePrefWidth(double height) {
-        double w = isVertical() ? getPrefBreadth() : getPrefLength();
+        double w = isVertical() ? getPrefBreadth(height) : getPrefLength();
         return w + vbar.prefWidth(-1);
     }
 
     @Override protected double computePrefHeight(double width) {
-        double h = isVertical() ? getPrefLength() : getPrefBreadth();
+        double h = isVertical() ? getPrefLength() : getPrefBreadth(width);
         return h + hbar.prefHeight(-1);
     }