13

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)

user1090694
  • 609
  • 4
  • 8
  • 16

2 Answers2

22

Try set maxHeight and maxWidth properties of GridPane.

maxHeight="Infinity" maxWidth="Infinity"

And childrens of GridPane should contain

GridPane.hgrow="always" GridPane.vgrow="always"
Qwertovsky
  • 1,086
  • 12
  • 13
  • 2
    Thank you, but what's the point of the maxHeight and maxWidth? That part didn't make any difference in my application. –  Nov 13 '15 at 22:45
14

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

GridPane.setHgrow(childElementOfGridPane, Priority.ALWAYS);
GridPane.setVgrow(childElementOfGridPane, Priority.ALWAYS);
Johannes
  • 2,732
  • 5
  • 23
  • 32