Constantly Update UI in Java FX worker thread
you need to make changes to the scene graph on the JavaFX UI thread.like this:
Task task = new Task<Void>() { @Override public Void call() throws Exception { int i = 0; while (true) { final int finalI = i; Platform.runLater(new Runnable() { @Override public void run() { label.setText("" + finalI); } }); i++; Thread.sleep(1000); } }};Thread th = new Thread(task);th.setDaemon(true);th.start();
Cosmetic change to Sebastian's code.
while (true) { final int finalI = i++; Platform.runLater ( () -> label.setText ("" + finalI)); Thread.sleep (1000); }