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);
}
}
Here is some sample code for integrating TableView with a Pagination control.
The code comes from Shakir Quasaroff's answer to an Oracle JavaFX forum request for a PaginatedTableView control. The sample code is a pure Java solution, rather than a Java Code/FXML hybrid as in the original question.
Sample program output:
Additionally, the third party, lgpl licensed TiwulFX library by Panemu provides advanced functionality for TableView (including pagination).
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:
A complete runnable example can be found here: https://gist.github.com/timbuethe/7becdc4556225e7c5b7b
I discovered a little problem when testing out the pagination code produced on this thread. When the size of the data == to the number of rows that one has set in a page, chaos (within the pages) would occur. In this case, an additional (blank) page is created and data refuses to show up on any of the pages. I believe that the following snippet should solve that issue (if anyone else is encountering the same problem as me). This snippet should come before declaring the Pagination variable.
Hope it helps!