0
private void updateUI(String text) {

 Platform.runLater(new Runnable() {
        @Override public void run() {
            System.out.println("Updating GUI...");
            textBox.setText(text);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

}

I'm using few threads on my JavaFx project. Those threads are reading some files and my GUI is being updated at the end, even though I'm trying to change it on the way.

I just want to add a delay after every change of my textBox value. But the problem is that the textBox value is not updated after every "Updating GUI..." It's value is being changed just at the end. How can I delay every change in my textBox?

I'm ok with the fact that GUI is updated after my threads are done..but I suspect that the value of the textBox is being changed many times instantly wich I want to change

UnguruBulan
  • 890
  • 4
  • 12
  • 24
  • 1
    your code blocks the EDT so that the update occurs after the thread sleep while the "controller" keeps pushing updates to the GUI. you need to slow down the calls to `updateUI`. – Timothy Truckle Feb 18 '17 at 19:50
  • You cannot `Thread.sleep()` on the FX Application thread - that needs to be done on a background thread. If all you are doing is changing the UI at some fixed time interval, it is better to use the Animation API for this kind of functionality anyway. – James_D Feb 18 '17 at 19:50

0 Answers0