title: Label not being automatically updated with thread in javafx
body: <p>Actually i'm a beginner to the java thread. For my learning purpose I've created a simple program. I don't know where i missed. </p>
  
  <p>Code:</p>
  
  <pre><code>package javaguithread;
  
  import javafx.fxml.FXML;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextField;
  
  public class Controller {
  
      Thread t1;
  
      @FXML
      TextField input;
  
      @FXML
      Label output;
  
      @FXML
      private void addData() {
          output.setText(input.getText());
      }
  
      public void initialize() {
  
          t1 = new Thread(() -&gt; {
  
              while (true) {
                  System.out.println(input.getText());
                  output.setText(input.getText());
              }
          });
  
          t1.start();
      }
  }
  </code></pre>
  
  <p>Error it show is </p>
  
  <pre><code>at com.sun.javafx.tk.Toolkit.checkFxUserThread(
  Toolkit.java:236)
  </code></pre>
  
  <p><b>Updated  </b></p>
  
  <p> 
  I've tried initializing the thread with the another class I've created. Hers's my code.
  </p>
  
  <pre><code>package javathreadgui;
  
  import javafx.application.Platform;
  import javafx.concurrent.Task;
  import javafx.fxml.FXML;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextField;
  
  public class Controller {
  
      private class GuiUpdater extends Task&lt;Void&gt; {
  
          Controller ctrl;
  
          GuiUpdater(Controller ctrl) {
              this.ctrl = ctrl;
          }
  
          @Override
          protected Void call() throws Exception {
              makeChanges();
              return null;
          }
  
          private void makeChanges(){
           while(true){
               Platform.runLater(() -&gt; {
                 ctrl.output.setText(ctrl.input.getText());  
               });
  
               System.out.println("test");
  
           }   
          }
  
      }
  
      @FXML
      TextField input;
  
      @FXML
      Label output;
  
      public void initialize() {
          System.out.println("Hello ");
  
          Task&lt;Void&gt; task = new GuiUpdater(this);
  
          Thread thread = new Thread(task);
  
          thread.setDaemon(true);
          thread.start();
      }
  
  }
  </code></pre>
  
  <p>It works preety well when i make console output as </p>
  
  <pre><code>System.out.println("test");
  </code></pre>
  
  <p>else the GUI freezes. What can i do for that?</p>