Reputation: 1094
I have a question about the HBox in JavaFX. If I add a new component to the HBox it's automatically added to the last component. Is there a possibility to get something like this:
[ {LABEL}{SPACE}{LABEL} ] => HBOX CONTAINER
Thank you for your help.
Remark: The Space must grow up with the Window when i resize it...
Upvotes: 0
Views: 1319
Reputation: 1907
The simplest way (if not using a different container like AnchorPane) is to insert an invisible, but expandible 'space' object:
void testLabelSpace(HBox box) {
Text first = new Text("first");
Text second = new Text("second");
Node space = new HBox();
HBox.setHgrow(space, Priority.ALWAYS);
box.getChildren().addAll(first, space, second);
}
Upvotes: 1
Reputation: 49185
Try to use HBox's static method setHgrow(...)
:
HBox.setHgrow(label1, Priority.ALWAYS);
Initial spacing value can be set by:
myHBox.setSpacing(val);
Upvotes: 1