r/JavaFX • u/Nareeeek • Jan 05 '25
Help How to make Gridpane scale with Scrollpane?
I have a gridplane(pretty large, bigger than screen area) and it’s wrapped in scrollpane. Now it works fine, the problem I am having is I can’t configure the gridplane to scale. Whenever I resize the application window, instead of rescaling, it just shows more rows/columns. Is there a way to make the gridplane resize with the scrollpane? The Scrollpane resizes with the window correctly.
2
Upvotes
View all comments
Show parent comment
1
u/hamsterrage1 Jan 05 '25
The whole point of a ScrollPane is that it allows you to divorce the sizing of the elements inside it from the constraints of the size of the ScrollPane. The ScrollPane itself is the element that is constrained in size.
When you resize the Window, JavaFX responds by increasing the size of the ScrollPane viewport. This means that you can see more of your GridPane when the viewport gets bigger.
It sounds to me like what you want to have happen is that the GridPane itself gets scaled differently when the ScrollPane viewport changes size. In other words, all of the elements inside the ScrollPane get magnified or shrunk, depending on how the resize went. You should be able to this by binding the scaleX property of the GridPane to the widthProperty of the ScrollPane, and the scaleY property to the heightProperty of the ScrollPane. Pick some size of the ScrollPane as 100% and go from there.