The HBox
and VBox
layouts are very similar, both lay out their children in a single line.
Common characteristics
If an HBox
or a VBox
have a border and/or padding set, then the contents will be layed out within those insets.
They lay out each managed child regardless of the child's visible property value; unmanaged children are ignored.
The alignment of the content is controlled by the alignment property, which defaults to Pos.TOP_LEFT
.
HBox
HBox
lays out its children in a single horizontal row from left to right.
HBox
will resize children (if resizable) to their preferred widths and uses its fillHeight property to determine whether to resize their heights to fill its own height or keep their heights to their preferred (fillHeight defaults to true).
Creating a HBox
// HBox example
HBox row = new HBox();
Label first = new Label("First");
Label second = new Label("Second");
row.getChildren().addAll(first, second);
VBox
VBox
lays out its children in a single vertical column from top to bottom.
VBox
will resize children (if resizable) to their preferred heights and uses its fillWidth property to determine whether to resize their widths to fill its own width or keep their widths to their preferred (fillWidth defaults to true).
Creating a VBox
// VBox example
VBox column = new VBox();
Label upper = new Label("Upper");
Label lower = new Label("Lower");
column.getChildren().addAll(upper, lower);