0
votes

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...

2

2 Answers

1
votes

Try to use HBox's static method setHgrow(...):

HBox.setHgrow(label1, Priority.ALWAYS);

Initial spacing value can be set by:

myHBox.setSpacing(val);
1
votes

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);
}