HBox child 不收缩

HBox child not shrinking

我有一个 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>

我的问题是,当我调整 window 大小时,empty 窗格正在增长,但它不会缩小到初始宽度(应用程序启动时的大小)以下。

显示正在(或未发生)事情的视频:https://jumpshare.com/v/0QriIiITUlSRgLMy4ev5

这是预期的行为还是 JavaFX 中的错误?

在FXML中,在BorderPane的定义中替换:

minWidth="-Infinity"

minWidth="0".

问题是您的 HBox 没有收缩,因为 BorderPane 本身不再收缩了。

最小宽度为 0 将确保 BorderPane 缩小,因此 HBox 也将调整大小。

我试过你的 FXML,经过这个小小的修改,布局似乎是正确的。