title: How to access components from different file controller?
body: <p>Suppose I have two FXML files: main and the one with the custom component. I want access to the main file components from the custom controller, like this:</p>
  
  <p>Main.fxml:</p>
  
  <pre><code>&lt;FlowPane&gt;
      &lt;children&gt;
          &lt;TextField fx:id="source" /&gt;
          &lt;CustomBox fx:id="cbox" /&gt;
      &lt;/children&gt;
  &lt;/FlowPane&gt;
  </code></pre>
  
  <p>Custom.fxml:</p>
  
  <pre><code>&lt;fx:root type="HBox"&gt;
      &lt;children&gt;
          &lt;Button fx:id="showButton" onAction="#show" text="Show" /&gt;
      &lt;/children&gt;
  &lt;/fx:root&gt;
  </code></pre>
  
  <p>CustomBox.java:</p>
  
  <pre><code>public class CustomBox extends HBox {
      @FXML
      private TextField source;
  
      public CustomBox() {
          FXMLLoader loader = new FXMLLoader(getClass().getResource("Custom.fxml"));
          loader.setRoot(this);
          loader.setController(this);
          try {
              loader.load();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @FXML
      protected void show() {
          System.out.println(source.getText());
      }
  }
  </code></pre>
  
  <p>But the method show() gives me NPE. How can I bind components and controllers from different files?</p>