Search code examples
javafxhbox

JavaFX HBox Component Alignment


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


Solution

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

    HBox.setHgrow(label1, Priority.ALWAYS);
    

    Initial spacing value can be set by:

    myHBox.setSpacing(val);