javafx Auto advance


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();