title: Calling a function on the start of a JavaFX project using SceneBuilder
body: <p>I created a GUI for my project using SceneBuilder and I set up all the button ID's and created a controller for the FXML file. I want to have a live clock running in the text area on launch and throughout the program. This is my first time using FXML to create a project in JavaFX so I'm confused as to where I should place this code. Normally the code works in a simple program without FXML and it is this code:</p>
  <pre><code>package com.example;
  import example; 
  
  public class Layout extends Application {
  
           TextArea clock;
  
  public void start(Stage stage) throws FileNotFoundException {  
           
           clock = new TextArea();
           clock.setEditable(false);
            BorderPane bp = new BorderPane();
            bp.setTop(clock);
   
            refreshClock();
  
           Scene scene = new Scene(bp);
  
          stage.setScene(scene);
          stage.show();
     }
  }
  
    private void refreshClock()
      {
          Thread refreshClock = new Thread()
             {  
                public void run()
                {  
                  while (true)
                  {
                      Date dte = new Date();
          
                      String topMenuStr = &quot;       &quot; + dte.toString();                       
                      clock.setText(topMenuStr); 
                             
                      try
                      {
                         sleep(3000L);
                      }
                      catch (InterruptedException e) 
                      {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                      }
                    
                  }  // end while ( true )
                   
              } // end run thread
           };
  
           refreshClock.start();
      }
  
  </code></pre>
  <p>When I attempt to do it my current progress in my Ui controller class, nothing pops up in the Text Area despite what code I do and I'm not sure what to do next. Should this code be in my main .java file? Here is what I tried:</p>
  <pre><code>
  package application;
  
  import java.util.Date;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.control.Button;
  import javafx.scene.control.TextField;
  import javafx.scene.control.TextArea;
  
  public class UiController {
      
      @FXML
      private TextArea clockTextArea;
  
  
  private void refreshClock()
      {
          Thread refreshClock = new Thread()
             {  
                public void run()
                {  
                  while (true)
                  {
                      Date dte = new Date();
          
                      String topMenuStr = &quot;       &quot; + dte.toString();                       
                      clockTextArea.setText(topMenuStr); 
                             
                      try
                      {
                         sleep(3000L);
                      }
                      catch (InterruptedException e) 
                      {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                      }
                    
                  }  // end while ( true )
                   
              } // end run thread
           };
  
           refreshClock.start();
      }
  
      
  
      
      public void initialize() {
          
          refreshClock();
      
      }
      
  
  </code></pre>