I'm trying to show a HBox which contains a list of checkboxes. Example:
HBox container = new HBox();
for (Weekday day: Weekday.values() )
{
container.getChildren().add( new CheckBox( day.getName() ) );
}
However this shows the days all on one line, as:
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
The window is not big enough to show them all on one line, and so I get a horizontal scrollbar. What I need is to show the days on two lines, e.g:
Sunday Monday Tuesday Wednesday
Thursday Friday Saturday
I've tried container.setPrefWidth()
but it just causes it to show Su.., Mo..
to truncate the text rather than moving them to the next line.
The JavaFX HBox component is a layout component which positions all its child nodes (components) in a horizontal row. The Java HBox component is represented by the class javafx. scene. layout. HBox .
The layout panes HBox and VBox are definitely the most basic layout containers in JavaFX 2.0. As you can already tell by their name, their purpose is to layout all their children in one horizontal row ( HBox ) or in one vertical column ( VBox ).
The TilePane layout pane places all of the nodes in a grid in which each cell, or tile, is the same size. Nodes can be laid out horizontally (in rows) or vertically (in columns).
HBox is a subclass of Pane that lays out its children next to each other, in a horizontal row. VBox is a subclass of Pane that lays out its children in vertical column. An HBox might be used as the bottom component in a BorderPane, making it possible to line up several components along the bottom of the border pane.
You should try using FlowPane. I tried it and got the result you've been seeking for.
The HBox layout pane provides an easy way for arranging a series of nodes in a single row
...
The nodes within a FlowPane layout pane are laid out consecutively and wrap at the boundary set for the pane. Nodes can flow vertically (in columns) or horizontally (in rows). A vertical flow pane wraps at the height boundary for the pane. A horizontal flow pane wraps at the width boundary for the pane.
source: http://docs.oracle.com/javafx/2/layout/builtin_layouts.htm#CHDGHCDG (its a useful read)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With