JavaFX TableView Paginator

前端 未结 3 1892
难免孤独
难免孤独 2020-11-29 04:04

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

public class SampleController implements Initializable {

    @FXML private TableView

        
3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 04:13

    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);
        ...
    }
    

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

提交回复
热议问题