Reputation: 1365
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.
Upvotes: 9
Views: 39672
Reputation: 49185
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.
Upvotes: 16
Reputation: 4578
You can use the Alignment method like
borderPane.setBottom(hBox);
borderPane.setAlignment(hBox,Pos.CENTER);
Upvotes: 2