Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+15 votes

Has anyone been successful in trying to make a gridpane scrollable? How'd you do it?

asked in CSC305 Fall 2023 by (1 point)

5 Answers

+4 votes

You can achieve this by wrapping your GridPane inside a ScrollPane.

Ideally you can edit it in the fxml file in scene builder and make the ScrollPane the parent, and the GridPane the child.

Or you can modify it in the code:
ScrollPane scrollPane = new ScrollPane(gridPane);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);

answered by (2.1k points)
+1

Thanks!

+2 votes

Another possibility to consider would be to include the 3rd party "ControlsFX" library in your project.

The GridView component looks rather promising, depending on the UI design you're trying to accomplish... https://controlsfx.github.io/features/gridview/

answered by (508 points)
0

Thank you Dr. Stonedahl!

+1 vote

You can use a scorllview and then include the gridpane within that

answered by (1 point)
0 votes

I put all of the cards into a flowPane and I put the flowPane into a scrollPane. It wont start scrolling and it won't show the scrollbar until you add enough cards to scroll off of the page, this messed me up for a little bit.

answered by (1 point)
0 votes

you can embed the Grid Pane within a ScrollPane. You should also use the setFitToWidth(true) and setFitToHeight(true) to ensure that the content of the GridPane resizes to fit the available space within the ScrollPane.

answered by (1 point)
...