将GridPane扩展为最大宽度和高度

时间:2013-02-26 11:16:21

标签: java javafx-2 fxml

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

我有以下内容:

<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>

并且我想将网格窗格扩展到由锚定窗格确定的限制(因此整个屏幕除了下部)

2 个答案:

答案 0 :(得分:16)

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

maxHeight="Infinity" maxWidth="Infinity"

GridPane的孩子应该包含

GridPane.hgrow="always" GridPane.vgrow="always"

答案 1 :(得分:10)

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

GridPane.setHgrow(childElementOfGridPane, Priority.ALWAYS);
GridPane.setVgrow(childElementOfGridPane, Priority.ALWAYS);