title: Changing the text of a label from a different class in JavaFX
body: <p>This question was already asked <a href="https://stackoverflow.com/questions/28529482/javafx-change-label-text-from-another-class-with-controller">here</a> but was not able to find any answers. I have reproduced a similar situation where I would like to change the text of a label from another class using the controller</p>
  
  <p>FXMLDocumentController.java</p>
  
  <pre><code>public class FXMLDocumentController implements Initializable {
  
      @FXML
      private Label label;
  
      @FXML
      private void handleButtonAction(ActionEvent event) {
          System.out.println("FXMLDocumentController.#handleButtonAction");
          label.setText("Hello World!");
          Connector.Connecting();
      }
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // TODO
      }    
  
      public void setLabelText(String text)
      {
          System.out.println("FXMLDocumentController.setLabelText(): Called");
          label.setText(text);
      }
  
  }
  </code></pre>
  
  <p>FXMLDocument.fxml</p>
  
  <pre><code>&lt;AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="demo5.FXMLDocumentController"&gt;
      &lt;children&gt;
          &lt;Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" /&gt;
          &lt;Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" /&gt;
      &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>Demo5.java</p>
  
  <pre><code>public class Demo5 extends Application {
  
      @Override
      public void start(Stage stage) throws Exception {
          Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
  
          Scene scene = new Scene(root);
  
          stage.setScene(scene);
          stage.show();
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          launch(args);
      }
  
  }
  </code></pre>
  
  <p>Connector.java</p>
  
  <pre><code>public class Connector {
      public static void Connecting() {
          try {
              System.out.println("Connector.Connecting(): Called");
  
              FXMLLoader loader = new FXMLLoader(FXMLDocumentController.class.getResource("FXMLDocument.fxml"));
              loader.load();
              FXMLDocumentController controller = (FXMLDocumentController) loader.getController();
  
              controller.setLabelText("Bye World");
          } catch (IOException ex) {
              Logger.getLogger(Connector.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p><strong>Output at Console</strong></p>
  
  <pre><code>Connector.Connecting(): Called
  FXMLDocumentController.setLabelText(): Called
  </code></pre>
  
  <p>But could see no changes in the label. Am I missing something major here ?</p>