我试图用按钮填充边框的底部容器。根据JavaFX文档,按钮应设置为prefHeight,宽度应填充容器。我将所有子项的maxWidth设置为无穷大,因此我知道子项的maxWidth不会阻止调整大小。参见下面的fxml。
<BorderPane>
<top>
<VBox>
<Label text="This is a message"/>
<HBox>
<TextField>Text 1</TextField>
<TextField>Text 2</TextField>
<TextField>Text 3</TextField>
</HBox>
</VBox>
</top>
<center>
<TableView>
</TableView>
</center>
<bottom>
<HBox maxWidth="Infinity">
<Button maxWidth="Infinity">Button 1</Button>
<Button maxWidth="Infinity">Button 2</Button>
<Button maxWidth="Infinity">Button 3</Button>
<Button maxWidth="Infinity">Button 4</Button>
<Button maxWidth="Infinity">Button 5</Button>
</HBox>
</bottom>
</BorderPane>
答案 0 :(得分:0)
hgrow将为子节点设置水平增长优先级。 P
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane xmlns="http://javafx.com/javafx/8">
<top>
<VBox>
<children>
<Label text="This is a message" />
<HBox>
<children>
<TextField>Text 1</TextField>
<TextField>Text 2</TextField>
<TextField>Text 3</TextField>
</children>
</HBox>
</children>
</VBox>
</top>
<center>
<TableView>
</TableView>
</center>
<bottom>
<HBox maxWidth="Infinity">
<children>
<Button maxWidth="Infinity" HBox.hgrow="ALWAYS">Button 1</Button>
<Button maxWidth="Infinity" HBox.hgrow="ALWAYS">Button 2</Button>
<Button maxWidth="Infinity" HBox.hgrow="ALWAYS">Button 3</Button>
<Button maxWidth="Infinity" HBox.hgrow="ALWAYS">Button 4</Button>
<Button maxWidth="Infinity" HBox.hgrow="ALWAYS">Button 5</Button>
</children>
</HBox>
</bottom>
</BorderPane>