In 2.1b10 the content display a graphic in a button with both a graphic and text defaults to centered behind the text rather than to the left of the text.
In 2.0.2 the graphics appeared to the left of the text.
In an app I had to add button.setContentDisplay(ContentDisplay.LEFT) so that buttons with text and graphics rendered as they had before.
It was only a minor issue for me - so this is logged more as an FYI - perhaps I should have been setting the content display explicitly earlier, but just didn't need to.
Attached is a demo screenshot from 2.1b10 with half the buttons converted to use button.setContentDisplay(ContentDisplay.LEFT)
Here is the utility method in my code which I use to create the a button with text and an icon:
// create a button with an icon
static public Button createIconButton(String buttonText, String imageLoc, String tooltipText, EventHandler<ActionEvent> actionEventHandler) {
final Button button = new Button(buttonText);
button.setTooltip(new Tooltip(tooltipText));
button.setMaxWidth(Double.MAX_VALUE);
button.setAlignment(Pos.CENTER_LEFT);
final ImageView imageView = new ImageView(new Image(getResource(imageLoc)));
imageView.setFitHeight(16);
imageView.setPreserveRatio(true);
button.setGraphic(imageView);
button.setContentDisplay(ContentDisplay.LEFT); // added to keep the display in 2.1b10 compatible with the display in previous versions.
VBox.setMargin(button, new Insets(0, 5, 0, 5));
button.setOnAction(actionEventHandler);
return button;
}
// get a resource relative to the application class.
static String getResource(String path) {
return Willow.class.getResource(path).toExternalForm();
}
In 2.0.2 the graphics appeared to the left of the text.
In an app I had to add button.setContentDisplay(ContentDisplay.LEFT) so that buttons with text and graphics rendered as they had before.
It was only a minor issue for me - so this is logged more as an FYI - perhaps I should have been setting the content display explicitly earlier, but just didn't need to.
Attached is a demo screenshot from 2.1b10 with half the buttons converted to use button.setContentDisplay(ContentDisplay.LEFT)
Here is the utility method in my code which I use to create the a button with text and an icon:
// create a button with an icon
static public Button createIconButton(String buttonText, String imageLoc, String tooltipText, EventHandler<ActionEvent> actionEventHandler) {
final Button button = new Button(buttonText);
button.setTooltip(new Tooltip(tooltipText));
button.setMaxWidth(Double.MAX_VALUE);
button.setAlignment(Pos.CENTER_LEFT);
final ImageView imageView = new ImageView(new Image(getResource(imageLoc)));
imageView.setFitHeight(16);
imageView.setPreserveRatio(true);
button.setGraphic(imageView);
button.setContentDisplay(ContentDisplay.LEFT); // added to keep the display in 2.1b10 compatible with the display in previous versions.
VBox.setMargin(button, new Insets(0, 5, 0, 5));
button.setOnAction(actionEventHandler);
return button;
}
// get a resource relative to the application class.
static String getResource(String path) {
return Willow.class.getResource(path).toExternalForm();
}
- duplicates
-
JDK-8117730 Image is overlapping the Button Text
- Closed
- relates to
-
JDK-8115371 Missing CSS docs: -fx-label-padding, -fx-graphic-vpos, more?
- Resolved