12

是否可以将网格窗格扩展到最大宽度和高度?

我有以下内容:

<fx:root type="javafx.scene.layout.AnchorPane" xmlns:fx="http://javafx.com/fxml"
         stylesheets="view/Style.css">
    <children>
        <GridPane xmlns:fx="http://javafx.com/fxml"
                  AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="128.0"
                  AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
                  hgap="10" vgap="10">
            <!--anything-->
        </GridPane>
    </children>
</fx:root>

我想将网格窗格扩展到锚窗格确定的限制(所以除了下部之外的整个屏幕)

4

2 回答 2

19

尝试设置 GridPane 的 maxHeight 和 maxWidth 属性。

maxHeight="Infinity" maxWidth="Infinity"

GridPane 的孩子应该包含

GridPane.hgrow="always" GridPane.vgrow="always"
于 2013-02-26T18:37:29.410 回答
14

如果您在没有 fxml 的情况下直接使用 JavaFX。代码是:

GridPane.setHgrow(childElementOfGridPane, Priority.ALWAYS);
GridPane.setVgrow(childElementOfGridPane, Priority.ALWAYS);
于 2015-09-24T11:23:24.200 回答