在 JavaFx 中将视图置于另一个视图之上

Centering a View on top of another view in JavaFx

我试图在锚定窗格中将一个视图置于另一个视图之上。

这是我的代码:

<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
    <children>
        <ListView fx:id="list" prefHeight="750.0" prefWidth="300.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
        <ProgressIndicator fx:id="bar" />
    </children>
</AnchorPane>

这是它的样子:

这是我的目标:

编辑:

更新代码以包含堆栈窗格

<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
          <children>
            <StackPane prefHeight="150.0" prefWidth="200.0">
              <children>
                <ListView fx:id="list" />
                <ProgressIndicator fx:id="bar" />
              </children>
            </StackPane>
          </children>
        </AnchorPane>

试试这个:

填充StackPane的关键是将ListView的maxHeight和maxWidth设置为Double.MAX_VALUE。

<children>
  <StackPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
     <children>
        <ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
        <ProgressIndicator maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" progress="0.44">
           <StackPane.margin>
              <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
           </StackPane.margin>
        </ProgressIndicator>
     </children>
  </StackPane>

The prefHeight and prefWidth for the StackPane and ListView may not reflect what you have in your original post. You can change these values to suit your needs. I also set Constraints on the StackPane so that it fills its Parent AnchorPane.

SceneBuilder 图片:

您可能需要设置 ProgressIndicator

的首选边