JavaFX - Prevent FlowPane from growing horizontally in VBox

857 Views Asked by At

How can I prevent the FlowPane layout from growing? My FlowPane layout is inside a VBox, which has a max width and wraps its content automatically when needed (works with TextFlow and HBox), except with FlowPane. So my problem is that my FlowPane layout won't observe its maxWidth property.

Preview

Also included:

FlowPane messagePane = new FlowPane();
messagePane.setPrefSize(VBox.USE_PREF_SIZE,VBox.USE_PREF_SIZE);
messagePane.setMaxWidth(VBox.USE_PREF_SIZE);
messagePane.setAlignment(Pos.CENTER);

And its content:

Label m = new Label(messageText);
m.setFont(Font.font("Calibri", FontWeight.SEMI_BOLD, 20));
m.setWrapText(true);
m.setAlignment(Pos.CENTER);
m.setTextAlignment(TextAlignment.CENTER);
m.setMaxWidth(FlowPane.USE_PREF_SIZE); //Works with constants only

Why doesn't it work as wanted?

0

There are 0 best solutions below