title: Access fields from another Controller in JavaFX
body: <p>I'm writing small application using JavaFX but I stuck with one problem.</p>
  
  <p>I have fxml files:</p>
  
  <pre><code>MainPane.fxml
  Stream.fxml
  Play.fxml
  </code></pre>
  
  <p>and each of them has its own controller:</p>
  
  <pre><code>MainPaneController.java
  StreamController.java
  PlayController.java
  </code></pre>
  
  <p>Where in MainPane is:</p>
  
  <pre><code>&lt;GridPane fx:controller="model.MainController" fx:id="mainGrid"
      xmlns:fx="http://javafx.com/fxml" alignment="CENTER" gridLinesVisible="true"&gt;
  
      &lt;children&gt;
          &lt;fx:include source="Stream.fxml"/&gt;
      &lt;/children&gt;
  
      &lt;children&gt;
          &lt;fx:include source="Play.fxml"/&gt;
      &lt;/children&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>Play.fxml has this field:</p>
  
  <pre><code>&lt;TextField fx:id="searchField" text="Search" onAction="#search"/&gt;
  </code></pre>
  
  <p>now when action (enter button) if fired I want to access and change a label in Stream.fxml as follows:</p>
  
  <pre><code>public class PlayController implements Initializable {
  
      @FXML
      private TextField searchField;
  
      @FXML
      protected void search() {
          System.out.println("Search");
          String text = searchField.getText();
          //how to access Label in StreamController
      }
  }
  </code></pre>
  
  <p>I would like to avoid binding like</p>
  
  <pre><code>MainPaneController &lt;-&gt; StreamController
  MainController &lt;-&gt; PlayController
  </code></pre>
  
  <p>and access fields like:</p>
  
  <pre><code>mainController.getStreamController.changeLabel(text)
  </code></pre>
  
  <p>because I hope there is some better way to do this.</p>