java - 如何创建一个永远在垂直方向滚动的滚动窗格?
问题描述
我不确定这是否可行,我在上面找不到任何东西,但我可以永远做一个滚动窗格滚动吗?一旦按下按钮,我就会不断地将新按钮和标签添加到窗口中,并最终到达底部。我可能设置错误,但这里是代码:
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);
}
}
}
推荐阅读
- android - Flutter App 在 realse 后无法连接到互联网
- python - python itertools groupby 过滤器使用
- java - 如何读取android studio项目文件夹中的文件?
- sql - 如何使用 dplyr 将此 SQL 代码转换为 R 脚本?
- reactjs - 使用服务器端渲染访问页面时出现 ReactJS 错误
- powershell - Dockerfile 和 MSI 安装
- html - 无序列表与 css 属性/值列不均匀:safari 上的 4
- python - 如何在 Python 的 Discord 机器人中声明哪个对象将预期的参数分开?
- spring - Spring-boot 中的 Apache Solr 分布式搜索
- html - css中前后伪元素的问题