Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Update the Screen in JavaFX after Each Loop

Tags:

binding

javafx

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.

like image 868
Kent Shikama Avatar asked Jan 31 '26 17:01

Kent Shikama


1 Answers

"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.

like image 154
user2885564 Avatar answered Feb 03 '26 11:02

user2885564



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!