T
T
Talik2016-02-19 15:08:29
Java
Talik, 2016-02-19 15:08:29

How to overcome Not on FX application thread Java FX?

Essence of the question: How to properly organize the application (preferably with examples)?
There is a form1 controller, there are elements on the form: Label, TextArea, ProgressIndicator
There is a class with logic.
There are three methods in the class, each one performs lengthy actions.
Each method cannot be executed before its predecessor, i.e. for correct operation, you need to follow the order of execution of method1, method2, method3
Task: For each method, its own indicator should work out
In the TextArea field, some explanatory text should be displayed (it doesn’t matter, just text)
Label should change during work (according to the results of working out methods ) (displays the amount of data)
Tried to organize according to the advice from the articlewww.cyberforum.ru/java-gui-javafx/thread1594963.html
Since long run methods, I create a task:
Service thread = new Service() {
@Override
protected Task createTask() {
return new Task() {
@Override
protected Integer call() throws Exception {
class.method 1
.......
there is no problem updating the TextArea. But if I try to update the Label, I get java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
in which direction to dig? Tell me how such applications are correctly organized?
I'm just learning Java FX and Java.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur, 2016-02-19
@timych

Call the method like this:

Platform.runLater(new Runnable() {

        @Override
        public void run() {
          runMyMethod();
        }
      });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question