changeset 4228:734434df77c4

RT-31479: Combobox is rendered outside of container
author jgiles
date Wed, 10 Jul 2013 16:34:19 +1200
parents 3d9f1fb7ad9c
children 3a7a4276dc6c
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java
diffstat 2 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java	Wed Jul 10 15:00:51 2013 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java	Wed Jul 10 16:34:19 2013 +1200
@@ -329,17 +329,16 @@
     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
         checkState();
 
-        double pw = 0.0;
         if (getItemCount() == 0) {
             if (placeholderRegion == null) {
                 updatePlaceholderRegionVisibility();
             }
             if (placeholderRegion != null) {
-                pw = placeholderRegion.prefWidth(height) + leftInset + rightInset;
+                return placeholderRegion.prefWidth(height) + leftInset + rightInset;
             }
         }
 
-        return Math.max(pw, computePrefHeight(-1, topInset, rightInset, bottomInset, leftInset) * 0.618033987);
+        return computePrefHeight(-1, topInset, rightInset, bottomInset, leftInset) * 0.618033987;
     }
 
     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
--- a/modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java	Wed Jul 10 15:00:51 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java	Wed Jul 10 16:34:19 2013 +1200
@@ -25,6 +25,7 @@
 
 package javafx.scene.control;
 
+import com.sun.javafx.tk.Toolkit;
 import javafx.css.PseudoClass;
 
 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
@@ -54,6 +55,8 @@
 import javafx.scene.Node;
 import javafx.scene.Scene;
 import javafx.scene.input.KeyCode;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Circle;
 import javafx.stage.Stage;
 import javafx.util.Callback;
 import javafx.util.StringConverter;
@@ -1026,4 +1029,32 @@
         
         new KeyEventFirer(comboBox).doKeyPress(KeyCode.ENTER);
     }
+
+    @Test public void test_rt31479() {
+        ComboBox<String> comboBox = new ComboBox<String>();
+
+        StageLoader stageLoader = new StageLoader(comboBox);
+        stageLoader.getStage().show();
+
+        final double widthBefore = comboBox.getWidth();
+
+        // add item
+        comboBox.getItems().add("Option 1");
+
+        // open and close combobox
+        comboBox.show();
+        comboBox.hide();
+
+        // set a placeholder
+        comboBox.setPlaceholder(new Circle(12, Color.RED));
+
+        // remove item
+        comboBox.getItems().clear();
+
+        // fire pulse (this allows layout to cause the size to grow)
+        Toolkit.getToolkit().firePulse();
+
+        // test size
+        assertEquals(widthBefore, comboBox.getWidth(), 0.00);
+    }
 }