[英]How to create a scrollpane that would scroll in a vertical direction forever?
我不確定這是否可行,但找不到任何東西,但是我可以使滾動窗格永遠滾動嗎? 按下按鈕后,我會不斷在窗口中添加新的按鈕和標簽,並最終到達底部。 我可能將其設置為錯誤,但這是代碼:
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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.