Kent Shikama
Kent Shikama

Reputation: 4060

How to Update the Screen in JavaFX after Each Loop

I current have a value property that is bound to a label as such

IntegerProperty value = new SimpleIntegerProperty(10);

// And then in the Constructor
label.textProperty().bindBidirectional(value, new NumberStringConverter());

And the value property is updated in a function which is called 10,000 times after the user presses a button as such

value.setValue(value.get() + 1);

However, when the user presses the button, the program "freezes" and then after finishing all its calculations it shows 10,000 on the label. I would like for the label to show the value "1" and then "2" all the way to "10,000" as it does its calculations.

Upvotes: 3

Views: 2065

Answers (1)

user2885564
user2885564

Reputation: 56

"Implementing long-running tasks on the JavaFX Application thread inevitably makes an application UI unresponsive. A best practice is to do these tasks on one or more background threads and let the JavaFX Application thread process user events."

This sentence is extract from the Oracle documentation : http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm

I had the same problem with a progress bar and I solved it by following these recommendations.

Upvotes: 4

Related Questions