How to position elements in a new line in Flow Pane layout in JavaFX?

4.2k Views Asked by At

I know that elements in Flow Pane layout in JavaFX are positioned next each other in one orientation. I want in the middle of this process to force JavaFX to put elements in a new line , to some extend like "\n" character in print method . How i can do this ?

2

There are 2 best solutions below

0
On

A blank full width node behaves like "\n" in FlowPane.

Region p = new Region();
p.setPrefSize(Double.MAX_VALUE, 0.0);
flowPane.getChildren().add(p);

I think this is effective in case you want to control line breaking as a node.

0
On

That isn't how FlowPane works. You may be better off using a GridPane so you can specify the number of rows/columns. Or you can use a composite layout and use a FlowPane for each row, then put all your FlowPanes in a VBox.