JavaFX How to make a GridPane fit to ScrollPane parent?

I need page with a grid where entering some data so, using SceneBuilder , I put a GridPane inside an AnchorPane. The gridpane I need has huge height so I wrap it inside a ScrollPane and make the ScrollPane fitting to AnchorPane. But now when I expand the window gridpane doesn’t resize like it doesn’t fit the ScrollPane. How Can I make gridpane resizing when I resize the window?


Set the fitToWidth property of the ScrollPane to true and make sure both the anchors of the ScrollPane are set.
You may also need to use appropriate constraints on the GridPane columns to resize the children of the GridPane.


<AnchorPane xmlns:fx="">
        <ScrollPane fitToWidth="true"
                <GridPane hgap="10">
                        <Insets topRightBottomLeft="10"/>
                        <ColumnConstraints /> 
                        <ColumnConstraints fillWidth="true" hgrow="ALWAYS" /> 
                        <Text text="Family Name:"/>
                        <TextField GridPane.columnIndex="1"/>

Leave a Reply

Your email address will not be published. Required fields are marked *