I'm really beginner with javaFX and probably I'm missing something, but here my issue: I should show some changes in my gui application sequentially.
My code looks like this (each method performs a change in the gui, but the final result is given by the last method of course):
public void updateGui()
{
Platform.runLater(() -> {
doFirstStuff();
doSecondStuff();
doThirdStuff();
});
}
It would be nice if between the execution of each method there was a little delay (1,2 or maybe 3 seconds) for give time to the user to see what happened in the application.
My attempt was put:
Thread.sleep(1000);
after each method call, but since the thread is the JavaFX Application Thread, the result is awful.
Another solution that comes up right now in my mind is:
execute each method in another thread with a Runnable like this:
() -> {
Platform.runLater(() -> {
doFirstStuff();
});
Thread.sleep(1000);
});
and in updateGui()
submit the task in a newSingleThreadExecutor()
and wait for the termination of each task. But I don't know, it doesn't seem a good solution.
What is the best way to achieve my goal?