【问题标题】:How to implement paging for a TableView in JavaFX? [duplicate]如何在 JavaFX 中为 TableView 实现分页? [复制]
【发布时间】:2013-06-20 03:00:16
【问题描述】:

我有JavaFx TableView,想实现tableView分页显示。 javaFx tableView如何实现分页显示?

【问题讨论】:

    标签: pagination javafx tableview


    【解决方案1】:

    您必须使用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 论坛,这个例子真的很糟糕。我想在这里提供一个经过整理的示例。

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2013-02-27
      • 2021-12-04
      • 2020-06-30
      • 2018-11-18
      • 2016-05-22
      • 2016-12-07
      • 2023-04-10
      • 2018-08-06
      相关资源
      最近更新 更多