1

拥有一个 2 行 2 列的 GridPane,将行约束设置为 50% 的高度会导致不需要的行为。

代码:

<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="..." stylesheets="@general.css" prefWidth="800" prefHeight="600">
    <top>
        <VBox>
            <!-- ... -->
        </VBox>
    </top>

    <bottom>
        <HBox>
            <!-- ... -->
        </HBox>
    </bottom>

    <center>
        <GridPane > 
            <children>

                <ScrollPane fx:id="tilePane" GridPane.columnIndex="0" GridPane.rowIndex="0">
                    <content>
                    </content>
                    <GridPane.margin>
                        <Insets bottom="2" left="2" right="2" top="2" />
                    </GridPane.margin>
                </ScrollPane>

                <TreeView fx:id="listPane" GridPane.columnIndex="0" GridPane.rowIndex="1">
                    <root>
                        <TreeItem value="Stages" />
                    </root>
                    <GridPane.margin>
                        <Insets bottom="2" left="2" right="2" top="2" />
                    </GridPane.margin>
                </TreeView>

                <ScrollPane fx:id="mapPane" GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.rowSpan="2">
                    <content>
                    </content>
                    <GridPane.margin>
                        <Insets bottom="2" left="2" right="2" top="2" />
                    </GridPane.margin>
                </ScrollPane>

            </children>

            <columnConstraints>
                <ColumnConstraints hgrow="ALWAYS" percentWidth="25"/>
                <ColumnConstraints hgrow="ALWAYS" />
            </columnConstraints>

            <rowConstraints>
                <RowConstraints vgrow="ALWAYS" percentHeight="50" />
                <RowConstraints vgrow="ALWAYS" percentHeight="50" />
            </rowConstraints>
        </GridPane>
    </center>
</BorderPane>

(底部提到的属性)

我预计这两行将以 50% 的比率共享它们的可用高度。他们这样做,但他们也消耗了比需要更多的空间。

带有和不带percentHeight指定的结果图片:

与百分比高度 没有百分比高度

我理解percentHeight错了,还是有其他方法?

4

0 回答 0