I am trying to learn JavaFX and convert a swing application to JavaFX. What I want to do is use JavaFX to display the progress of a program.
What I was previously do
Try calling from within the UI thread as so:
public void setText(final String newText) {
Platform.runLater(new Runnable() {
@Override
public void run() {
btn.setText(newText);
}
});
}
Anytime you want to make changes to an element of the UI, it must be done from within the UI thread. Platform.runLater(new Runnable()); will do just that. This prevents blocking, and other strange obscure UI-related bugs and exceptions from occurring.
Hint: what you have read/seen with the Platform.runLater being called in the startup of the app, and on timers is usually a way to load most of the UI immediately, then fill in the other parts after a second or two (the timer) so that not to block at startup. But Platform.runLater is not only for startup, it's for any time you need to change/use/interact-with a UI element.