I apologize in advance for a lot of text, but I come back to this problem the second day and tried several solutions, plus I did not receive a working answer on stackoverflow. So - I hope for help here.
Essence: on the GUI (JavaFX) there is a button that should launch two processes: the main program code (about 2 seconds) and the wait gif, which runs on top of the GUI. Accordingly, when the code is executed - the GIF is completed.
What I have done now:
The button's action method blocks the isStarted flag, which gets true when the button is pressed and false after the completion of the main code. In the main, before launching the GUI, I created a Task, which checks the flag in an infinite loop and, as soon as it gets true, it starts my gif with a separate showGif() method.
Result: the stream starts before the main code, the cycle is spinning, the GIF does not open - showGif() method stops at pane.setCenter(hb) . I added Platform.runLater() before calling the showGif() method in Task:
Now the cycle works completely, but the showGif() method is executed only after all the main code. GIF opens, but no longer needed.
I also tried the call to the showGif() method via Platform.runLater() directly in the button method, without any cycles, flags and Tasks - the result was the same (the GIF starts, but at the end of the program.) I added three seconds of delay to the main code, in case the GIF just didn't have enough time - the result is the same.
Tell me what am I doing wrong? I don't see the options.