gpt4 book ai didi

java - 如何创建一个永远在垂直方向滚动的滚动 Pane ?

转载 作者:太空宇宙 更新时间:2023-11-04 09:48:40 25 4
gpt4 key购买 nike

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

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());

最佳答案

你已经快到了,你现在需要做的就是将滚动 Pane 添加为容器的子级

        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);
}


}

}

关于java - 如何创建一个永远在垂直方向滚动的滚动 Pane ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55089282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com