java 将 GridPane 扩展到最大宽度和高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15087666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:26:22  来源:igfitidea点击:

expand a GridPane to max width and height

javajavafx-2fxml

提问by user1090694

is it possible to expand a grid pane to max width and height?

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

i have the following:

我有以下几点:

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

and i'd like to expand the grid pane to the limits determined by the anchor pane (so whole screen except the lower part)

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

回答by Qwertovsky

Try set maxHeight and maxWidth properties of GridPane.

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

maxHeight="Infinity" maxWidth="Infinity"

And childrens of GridPane should contain

GridPane 的孩子应该包含

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

回答by Johannes

If you are using JavaFX directly without fxml. The code is:

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

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