如何创建一个永远在垂直方向滚动的滚动窗格?

How to create a scrollpane that would scroll in a vertical direction forever?

我不确定这是否可行,而且我在上面找不到任何东西,但我可以让滚动窗格永远滚动吗? 一旦按下按钮,我就会不断地在 window 中添加新的按钮和标签,并最终到达底部。 我可能设置有误,但这是代码:

BorderPane bp = new BorderPane();
GridPane gp = new GridPane();
Button b = new Button("click");
gp.add(b, 1, 1);
ScrollPane sp = new ScrollPane(gp);
bp.setTop(sp);
b.setOnAction(e -> createLabel());

就快完成了,您现在需要做的就是将滚动窗格添加为任何容器的子项

        GridPane gp = new GridPane();
        Button b = new Button("click");
        gp.add(b, 1, 1);
        b.setOnAction(e -> createLabel());

        ScrollPane sp = new ScrollPane(gp);

        container.add(sp); // where container is whatever node that'll contain the gridpane.

使用此代码

public class Controller {
    @FXML private VBox topLevelContainer; // root fxml element

    @FXML
    void initialize(){

        GridPane gridPane = new GridPane();
        ScrollPane sp = new ScrollPane(gridPane);
        topLevelContainer.getChildren().add(sp);

        // add a 100 buttons to 0th column
        for (int i = 0; i < 100; i++) {
            gridPane.add(new Button("button"),0,i);
        }


    }

}