diff --git a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledSkinBase.java b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledSkinBase.java --- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledSkinBase.java +++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledSkinBase.java @@ -719,7 +719,28 @@ } @Override protected double computeMaxWidth(double height) { - return getSkinnable().prefWidth(height); + // Get the preferred width of the text + final Labeled labeled = getSkinnable(); + final Font font = text.getFont(); + final String string = labeled.getText(); + boolean emptyText = string == null || string.isEmpty(); + final Insets padding = getInsets(); + Insets labelPadding = labeled.getLabelPadding(); + double widthPadding = padding.getLeft() + padding.getRight() + labelPadding.getLeft() + labelPadding.getRight(); + double textWidth = emptyText ? 0 : Utils.computeTextWidth(font, string, 0); + + // Now add on the graphic, gap, and padding as appropriate + final Node graphic = labeled.getGraphic(); + if (isIgnoreGraphic()) { + return textWidth + widthPadding; + } else if (isIgnoreText()) { + return graphic.maxWidth(-1) + widthPadding; + } else if (labeled.getContentDisplay() == ContentDisplay.LEFT + || labeled.getContentDisplay() == ContentDisplay.RIGHT) { + return textWidth + labeled.getGraphicTextGap() + graphic.maxWidth(-1) + widthPadding; + } else { + return Math.max(textWidth, graphic.maxWidth(-1)) + widthPadding; + } } @Override protected double computeMaxHeight(double width) { diff --git a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListCellSkin.java b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListCellSkin.java --- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListCellSkin.java +++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListCellSkin.java @@ -39,9 +39,12 @@ @Override protected double computePrefWidth(double height) { double pref = super.computePrefWidth(height); + double max = super.computeMaxWidth(height); + double pw = Math.min(pref, max); + ListView listView = getSkinnable().getListView(); return listView == null ? 0 : - listView.getOrientation() == Orientation.VERTICAL ? pref : Math.max(pref, getCellSize()); + listView.getOrientation() == Orientation.VERTICAL ? pw : Math.max(pw, getCellSize()); } @Override protected double computePrefHeight(double width) {