作为布局,我有一个Pane
。
更改窗口大小后,如何始终将按钮的位置设置在右角?
Pane root = new Pane();
Button b = new Button("Button ");
b.setLayoutX(100);
b.setLayoutY(0);
root.getchildren().add(b);
Pane
不太适合这种布局。您可以使用
StackPane
:这将使每个孩子都对准角,边的中心或中心。
AnchorPane
:默认情况下,此布局与Pane
相同,但是如果设置锚点,则可以设置子项与顶部,左侧,右侧和/或顶部之间的距离底部。
示例:
AnchorPane root = new AnchorPane();
Button b = new Button("Button ");
// place button in the top right corner
AnchorPane.setRightAnchor(b,0d); // distance 0 from right side of
AnchorPane.setTopAnchor(b,0d); // distance 0 from top
root.getChildren().add(b);