Please how can I add a GridPane to a ScrollPane that I have in my fxml file with javafx code ?
Asked
Active
Viewed 1,018 times
1 Answers
1
If your ScrollPane
has been defined in an FXML
file, you need to add a reference to it within your Controller
class. This is done along with any other instance fields you need to define (at the top of your controller class). Since the node is defined in an FXML
document, you will annotate your Java code with the @FXML
annotation:
@FXML
private ScrollPane myScrollPane;
This essentially tells JavaFX that the ScrollPane
is created in the FXML
document, and not within your Java class.
The ScrollPane
has a Content
property that holds the node you want.
So you would simply set your GridPane
as the Content
of the ScrollPane
:
scrollPane.setContent(myGridPane);

Zephyr
- 9,885
- 4
- 28
- 63
-
That didn't work, is there a property that I should add to be able to populate a scrollPane that I already have in My fxml file? – learner Aug 26 '18 at 18:57
-
1My answer addresses exactly that... What about my answer doesn't work? Maybe you need to update your question to show more code. – Zephyr Aug 26 '18 at 19:24