答案 0 :(得分:2)
您必须使用Pagination控件并实现页面工厂。为每个应显示的页面调用工厂,您可以使用其参数pageIndex为TableView提供项目的子列表:
TableView table = ...
private Node createPage(int pageIndex) {
int fromIndex = pageIndex * rowsPerPage;
int toIndex = Math.min(fromIndex + rowsPerPage, data.size());
table.setItems(FXCollections.observableArrayList(data.subList(fromIndex, toIndex)));
return new BorderPane(table);
}
@Override
public void start(final Stage stage) throws Exception {
Pagination pagination = new Pagination((data.size() / rowsPerPage + 1), 0);
pagination.setPageFactory(this::createPage);
...
}
可在此处找到完整的可运行示例: https://gist.github.com/timbuethe/7becdc4556225e7c5b7b
PS:我关注了jewelsea链接到Oracle JavaFX论坛,这个例子非常糟糕。我想在这里提供一个清理过的例子。