我有一个 BorderPane
作为根元素,一个 HBox
在它的顶部。在 HBox
中,我有 5 个 AnchorPane
,其中 4. 作为间隔物。这是精简的 FXML:
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="710.0" prefWidth="1190.0" stylesheets="@style.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<top>
<HBox prefHeight="70.0" BorderPane.alignment="CENTER">
<children>
<AnchorPane prefHeight="70.0" prefWidth="200.0">
...
</AnchorPane>
<AnchorPane prefHeight="70.0" prefWidth="200.0">
...
</AnchorPane>
<AnchorPane prefHeight="70.0" prefWidth="200.0">
...
</AnchorPane>
<AnchorPane id="empty" minWidth="0.0" prefHeight="70.0" prefWidth="0.0" HBox.hgrow="ALWAYS" />
<AnchorPane prefHeight="70.0">
...
</AnchorPane>
</children>
</HBox>
</top>
</BorderPane>
我的问题是,当我调整窗口大小时,空
Pane 正在增长,但它没有缩小到初始宽度(应用程序启动时的大小)以下。
显示正在发生(或未发生)的视频:https://jumpshare.com/v/0QriIiITUlSRgLMy4ev5
这是预期的行为还是 JavaFX 中的错误?
最佳答案
在 FXML 中,在 BorderPane
的定义中替换:
minWidth="-Infinity"
与
minWidth="0".
问题是您的 HBox
没有缩小,因为 BorderPane
本身没有再缩小。
最小宽度为 0 将确保 BorderPane
缩小,因此 HBox
也将调整大小。
我已经尝试过您的 FXML,通过这个小的修改布局似乎是正确的。
关于java - HBox child 不收缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609861/