简体   繁体   English

在BorderPane中居中对象

[英]Center an object in BorderPane

In JavaFX, how to center an object in the top or bottom compartment in BorderPane layout? 在JavaFX中,如何在BorderPane布局中将对象置于顶部或底部隔间中?

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. 并且hBox出现在BorderPane borderPane底部隔层的左侧。我希望它位于底部的中心。 Thanks. 谢谢。

The default alignment for borderpane positions are: borderpane位置的默认对齐方式是:

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对齐更改为:

hBox.setAlignment(Pos.CENTER);

Refer to java API documentation for more info. 有关更多信息,请参阅Java API文档。

You can use the Alignment method like 您可以使用Alignment方法

borderPane.setBottom(hBox);
borderPane.setAlignment(hBox,Pos.CENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM