javafx - JavaFx 窗格按钮位置
问题描述
作为布局,我有一个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);
推荐阅读
- google-sheets - 当列 D 小于 C 的 50% 时,我如何让谷歌表格工作,并在发生这种情况时将颜色更改为琥珀色
- python - 如何根据 Pandas 中的条件为数据框子集的列分配值?
- android - 如何获得具有特定值的光标行
- java - 为什么我的选择设备活动不运行?
- javascript - 如何获取p元素内的所有跨度数据属性
- angular - 如何让 vsCode 意识到自动完成的深度依赖导入?
- database - 在 Postgresql 中从另一个更新大表需要很长时间(超过 6 小时)
- flutter - Flutter 安全存储更改路线
- javascript - 创建数组并组合键
- matlab - 如何在matlab中使用移动窗口计算梯度和相关系数?