import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ScrollPaneSample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        primaryStage.setTitle("Scroll Pane Example!");

        int N = 20;
        Node[] nodes = new Node[N];

        for (int i = 0; i < N; i++) {
            final int index = i;
            Button button = new Button();
            button.setText("Button: " + index);
            button.setOnAction((e) -> System.out.printf("Button is pressed: %d%n", index));
            nodes[i] = button;
        }

        VBox buttonsPane = new VBox(5, nodes);
        ScrollPane scrollPane = new ScrollPane(buttonsPane);

        StackPane root = new StackPane();
        root.getChildren().add(scrollPane);
        root.setStyle("-fx-padding: 10;" +
                "-fx-border-style: solid inside;" +
                "-fx-border-width: 2;" +
                "-fx-border-insets: 5;" +
                "-fx-border-radius: 5;" +
                "-fx-font-size: 64px;" +
                "-fx-border-color: blue;");

        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }
}
