In JavaFX, how to center an object in the top or bottom compartment in BorderPane layout?
I have:
borderPane.setBottom(hBox);
And hBox appears on the left side of the bottom compartment of BorderPane borderPane
.And I want it to be in the center of the bottom. Thanks.
The default alignment for borderpane positions are:
top: Pos.TOP_LEFT
bottom: Pos.BOTTOM_LEFT
left: Pos.TOP_LEFT
right: Pos.TOP_RIGHT
center: Pos.CENTER
To change this for different alignment use:
BorderPane.setAlignment(child, Pos.CENTER);
BorderPane.setMargin(child, new Insets(12,12,12,12)); // optional
borderPane.setBottom(child);
You may also change the child HBox alignment as:
hBox.setAlignment(Pos.CENTER);
Refer to java API documentation for more info.
You can use the Alignment method like
borderPane.setBottom(hBox);
borderPane.setAlignment(hBox,Pos.CENTER);
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