安
AnchorPane
不调整没有约束的子级的大小。你需要设置
rightAnchor
和
leftAnchor
的约束条件
HBox
. (您也可以简单地使用
Hbox
作为根。)
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="stackoverflow.labeltest.Controller">
<children>
<HBox AnchorPane.rightAnchor="0" AnchorPane.leftAnchor="0">
<children>
<Label fx:id="label"/>
</children>
</HBox>
</children>
</AnchorPane>