Search code examples
javafxscrollpanegridpane

JavaFX - ScrollPane within GridPane


I want a ScrollPane in my application window which doesn't fill the whole scene, but only takes up part of it, because I want to place a button beneath it.

Like in this sketch: https://i.sstatic.net/cxizX.png

I tried using a GridPane, but I can only put Nodes as children of the GridPane, which doesn't work because the ScrollPane is not a Node.

public void start(Stage stage) throws Exception {
    var root = new GridPane();
    var scene = new Scene(root, 400, 400);

    var scrollPane = new ScrollPane();
    root.add(scrollPane, 0, 0); // Not possible

    var button = new Button();
    root.add(button, 0, 1);

    stage.setScene(scene);
    stage.show();
}

Solution

  • Slaw's comment: javafx.scene.control.ScrollPane definitely is a javafx.scene.Node. The class hierarchy is: ScrollPane → Control → Region → Parent → Node