title: Multiple FXML files with controllers for each file - TextArea not displaying text properly after append
body: <p>I want to divide my FXML into smaller files, each having its own controller. In main I create instance for each controller and get access to <code>textAreaSample</code> and trying to append text. I don't see text is changing. Why? <code>Alert</code> is displaying text from this <code>TextArea</code>:</p>
  
  <pre><code>alert.setContentText(textAreaSample.getText());
  </code></pre>
  
  <p>I don't know how to set all fxml files and controllers. How should I set all of this?</p>
  
  <p>Here is my main `sample.fxml' file: </p>
  
  <pre><code>&lt;GridPane fx:controller="sample.ControllerSample"
        xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"&gt;
  
      &lt;fx:include fx:id="sending" source="Sending.fxml" GridPane.columnIndex="0" GridPane.rowIndex="0"/&gt;
  
      &lt;TextArea fx:id="textAreaSample" prefWidth="200" prefHeight="200"
            GridPane.columnIndex="1" GridPane.rowIndex="0" text="Sample"&gt;
      &lt;/TextArea&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>and its controller:</p>
  
  <pre><code>public class ControllerSample {
  
      @FXML
      private TextArea textAreaSample;
  
      public ControllerSample() {}
  
      public TextArea getTextAreaSample() {
          return textAreaSample;
      }
  
      public void setTextAreaSample(TextArea textAreaSample) {
          this.textAreaSample = textAreaSample;
      }
  }
  </code></pre>
  
  <p>Now I have <code>Sending.fxml</code> file:</p>
  
  <pre><code>&lt;GridPane fx:controller="sample.ControllerSending"
            xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"&gt;
  
          &lt;fx:include fx:id="sendingPhotos" source="SendingPhotos.fxml" GridPane.columnIndex="0" GridPane.rowIndex="0"/&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>and its controller:</p>
  
  <pre><code>public class ControllerSending {
  
      public ControllerSending() {}
  }
  </code></pre>
  
  <p>Here is <code>SendingPhotos.fxml</code> code:</p>
  
  <pre><code>&lt;TextArea xmlns="http://javafx.com/javafx"
        xmlns:fx="http://javafx.com/fxml"
        fx:controller="sample.ControllerSendingPhotos" fx:id="textAreaSendingPhotos" prefWidth="200" prefHeight="200"
        text="Photos"/&gt;
  </code></pre>
  
  <p>and controller:</p>
  
  <pre><code>public class ControllerSendingPhotos {
  
      @FXML
      private TextArea textAreaSendingPhotos;
  
      public ControllerSendingPhotos() {}
  
      public TextArea getTextAreaSendingPhotos() {
          return textAreaSendingPhotos;
      }
  
      public void setTextAreaSendingPhotos(TextArea textAreaSendingPhotos) {
          this.textAreaSendingPhotos = textAreaSendingPhotos;
      }
  }
  </code></pre>
  
  <p>Now <code>Main.java</code> code:</p>
  
  <pre><code>public class Main extends Application {
  
      @Override
      public void start(Stage primaryStage) throws Exception {
  
          FXMLLoader loaderSample = new FXMLLoader(getClass().getResource("sample.fxml"));
          FXMLLoader loaderSending = new FXMLLoader(getClass().getResource("Sending.fxml"));
          FXMLLoader loaderSendingPhotos = new FXMLLoader(getClass().getResource("SendingPhotos.fxml"));
  
          loaderSample.load();
          loaderSending.load();
          loaderSendingPhotos.load();
  
          ControllerSample controllerSample = (ControllerSample) loaderSample.getController();
          ControllerSending controllerSending = (ControllerSending) loaderSending.getController();
          ControllerSendingPhotos controllerSendingPhotos = (ControllerSendingPhotos) loaderSendingPhotos.getController();
  
          TextArea textAreaSample = controllerSample.getTextAreaSample();
          textAreaSample.setText("\ndebug textAreaSample\n");
  
          Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "");
  
          alert.setContentText(textAreaSample.getText());
          alert.showAndWait();
  
          //TextArea textAreaSendingPhotos = controllerSendingPhotos.getTextAreaSendingPhotos();
          //textAreaSendingPhotos.appendText("\ndebug textAreaSendingPhotos\n");
  
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
          primaryStage.setTitle("Hello World");
          primaryStage.setScene(new Scene(root, 800, 400));
          primaryStage.show();
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Edit: I define <code>ControllerSending</code> in <code>ControllerSample</code> with getters and setters? And then in <code>ControllerSending</code> I define <code>ControllerSendingPhoto</code> with getters and setters? And then in Main to declare <code>ControllerSendingPhotos</code> I use <code>controllerSample.getControllerSending().getControllerSendingPhotos()</code>?</p>