本文介绍了JavaFx窗格按钮位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为布局,我有一个Pane
.更改窗口大小后,如何始终将按钮的位置设置在右角?
As a layout I have a Pane
.How do I set the position of a button always in the right corner when windows size is changed?
Pane root = new Pane();
Button b = new Button("Button ");
b.setLayoutX(100);
b.setLayoutY(0);
root.getChildren().add(b);
推荐答案
Pane
不适用于这种布局.您可以使用
Pane
is not a good fit for this kind of layout. You could use
-
StackPane
:这将使每个子项与角,边的中心或中心对齐.
StackPane
: This will align every single child to a corner, center of an edge or the center though.
AnchorPane
:默认情况下,此布局与Pane
相同,但是如果设置锚点,则可以设置子项到顶部,左侧,右侧和/或底部的距离.
AnchorPane
: By default this layout works the same as Pane
, but if you set anchors, you can set the distance of a child from the top, left, right and/or bottom.
示例:
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);
这篇关于JavaFx窗格按钮位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!