我有以下代码:
<VBox id="menu" styleClass="menu" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.app.menu.MenuController">
<stylesheets>
<URL value="@menu.css"/>
</stylesheets>
<Button text="Customers" onAction="#handleCustomers" />
<Button text="Suppliers" onAction="#handleSuppliers" />
<Separator/>
<Button text="Families" onAction="#handleFamilies" />
<Button text="Products" onAction="#handleProducts" />
<Separator/>
</VBox>
这会生成一组堆叠的按钮(根据需要),但它们不会占据容器的整个宽度。
如果我试试这个:
我有以下代码:
<VBox id="menu" styleClass="menu" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.app.menu.MenuController">
<stylesheets>
<URL value="@menu.css"/>
</stylesheets>
<AnchorPane>
<Button text="Customers" onAction="#handleCustomers" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
<Button text="Suppliers" onAction="#handleSuppliers" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
<Separator/>
<Button text="Families" onAction="#handleFamilies" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
<Button text="Products" onAction="#handleProducts" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
<Separator/>
</AnchorPane>
</VBox>
然后我水平调整了按钮的大小,但它们不再堆叠。我无法使用 FXML 在 Java FX 中实现这一点。
所需的输出将是这样的:
跃然一笑
回首忆惘然
萧十郎
慕尼黑5688855
相关分类