changeset 7732:029bcb15c1e5

RT-36453 [ColorPicker, Modena] Colorpicker changes size depending on the currently selected color Reviewed by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 20 Aug 2014 15:00:42 +0200
parents f92fde766ac3
children 9130fc16c129
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java	Wed Aug 20 13:31:59 2014 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java	Wed Aug 20 15:00:42 2014 +0200
@@ -187,6 +187,7 @@
         // create displayNode
         displayNode = new Label();
         displayNode.getStyleClass().add("color-picker-label");
+        displayNode.setManaged(false);
 
         // label graphic
         pickerColorBox = new PickerColorBox();
@@ -204,6 +205,21 @@
     }
 
 
+    @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
+        if (!colorLabelVisible.get()) {
+            return super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset);
+        }
+        String displayNodeText = displayNode.getText();
+        double width = 0;
+        for (String name : colorNameMap.values()) {
+            displayNode.setText(name);
+            width = Math.max(width, super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset));
+        }
+        displayNode.setText(formatHexString(Color.BLACK)); // #000000
+        width = Math.max(width, super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset));
+        displayNode.setText(displayNodeText);
+        return width;
+    }
 
     private void updateComboBoxMode() {
         List<String> styleClass = getSkinnable().getStyleClass();