javafx Pagination Auto advance

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Pagination p = new Pagination(10);

Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), event -> {
    int pos = (p.getCurrentPageIndex()+1) % p.getPageCount();
    p.setCurrentPageIndex(pos);
}));
fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
fiveSecondsWonder.play();

stage.setScene(new Scene(p));
stage.show();

This advances the pagination every 5 seconds.

How it works

Pagination p = new Pagination(10);

Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), event -> {

fiveSecondsWonder is a timeline that fires an event every time it finishes a cycle. In this case the cycle time is 5 seconds.

    int pos = (p.getCurrentPageIndex()+1) % p.getPageCount();
    p.setCurrentPageIndex(pos);

Tick the pagination.

}));
fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);

Set the timeline to run forever.

fiveSecondsWonder.play();


Got any javafx Question?