java - 如何在 FXML 中将 Button 与 VBox 的底部对齐?
问题描述
我在 a 中有一些按钮VBox
。我想将最后一个按钮对齐到 VBox 的底部。有没有办法做到这一点?
我试过这个答案,但没有奏效。
这是我的代码:
<VBox fx:id="presetVBox" prefHeight="580.0" prefWidth="180.0" style="-fx-background-color: white;">
<padding>
<Insets left="10.0" right="10.0"/>
</padding>
<Button fx:id="preset1Button" maxWidth="Infinity" mnemonicParsing="false"
prefWidth="Infinity" text="Load Preset 1">
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</Button>
<Button fx:id="preset2Button" maxWidth="Infinity" mnemonicParsing="false"
prefWidth="Infinity" text="Load Preset 2">
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</Button>
<Button fx:id="savePresetButton" maxWidth="Infinity" mnemonicParsing="false"
prefWidth="500.0" text="Save">
<!-- This button needs to aligned to the bottom of the VBox -->
<VBox.margin>
<Insets top="161.0"/>
</VBox.margin>
</Button>
</VBox>
解决方案
Region
在按钮和最后一个孩子之前的孩子之间添加一个空白。如果VBox.vgrow
将此节点的属性设置为ALWAYS
,VBox
则调整其大小以占用剩余空间:
<VBox fx:id="presetVBox" prefHeight="580.0" prefWidth="180.0" style="-fx-background-color: white;">
<padding>
<Insets left="10.0" right="10.0"/>
</padding>
...
<Button fx:id="preset2Button" maxWidth="Infinity" mnemonicParsing="false"
prefWidth="Infinity" text="Load Preset 2">
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</Button>
<Region VBox.vgrow="ALWAYS" />
<Button fx:id="savePresetButton" maxWidth="Infinity" mnemonicParsing="false"
prefWidth="500.0" text="Save">
<!-- This button needs to aligned to the bottom of the VBox -->
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</Button>
</VBox>
推荐阅读
- c# - 我怎样才能为每一个点制作特殊的颜色和尺寸?(图形、油漆等)
- python - Python structlog 中有没有办法将键从“记录器”更改为“命名空间”?
- javascript - Window Scroll event doesn't work in Microsoft Edge
- javascript - 向 JSP 传递/公开 VXML 应用程序根文档变量
- jquery - CodeMirror,在 keyup 上更新 iframe 脚本
- mysql - 两张表之间的差异显示了一些相似之处
- javascript - 在不同时间发生 API 调用的最佳方式是什么?
- c# - 重新加载 Jquery DataGrid 表 - 不工作
- html - Fonts are blocked by firefox Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at firefox
- spring-mvc - 无法从没有按钮的情况下调用一个按钮