JavaFX TableView Paginator [英] JavaFX TableView Paginator

查看:193
本文介绍了JavaFX TableView Paginator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在TableView paginator中使用。?。这个例子......

How use in TableView paginator.?.For This exmple...

public class SampleController implements Initializable {

    @FXML private TableView<Student> table;
    @FXML private TableColumn<Student, Integer> id;
    @FXML private TableColumn<Student, String> name;
    @FXML private ObservableList<Student> list = FXCollections.observableArrayList();
    //  @FXML private Pagination pagination;
    // 
    private StudentSQL ssql = new StudentSQL();
    private Stage stage = new Stage();
    private String row;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        id.setCellValueFactory(new PropertyValueFactory<Student, Integer>("id"));
        name.setCellValueFactory(new PropertyValueFactory<Student, String>("name"));
        list = ssql.students();
        table.setItems(list);
    }
}


推荐答案

你必须使用 Pagination 控件和实现页面工厂。为每个应显示的页面调用工厂,您可以使用其参数pageIndex为TableView提供项目的子列表:

You have to use the Pagination control and implement a page factory. The factory is called for every page that should be displayed and you can use its parameter, the pageIndex, to provide a sublist of items to the 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

A complete runnable example can be found here: https://gist.github.com/timbuethe/7becdc4556225e7c5b7b

这篇关于JavaFX TableView Paginator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆