The timer is running its code on a separate thread from the JavaFX UI thread, and the UI thread is the only one that is allowed to make changes to elements of the user interface. This is why we had to wrap: Platform.runLater(() -> { /* code here */ } );
around the imageview.setImage(...) method, to ask the JavaFX UI thread to schedule some code to be run soon (but not immediately). You're probably already doing this inside of your displayFrame()
method.
So, the simplest fix is to change your code to use:
Platform.runLater(() -> {
currentTimeLabel.setText(getTime(chosenVideo.getCurrentFrameNum()));
});
One unrelated tip for improving the elegance of your code:
instead of having a getTime(...)
converter method inside of your Controller class, why not have your Video class provide a getCurrentTime()
method? (Converting between frames and seconds should be the Video class's responsibility, not the UI Controller's responsibility!)