title: JavaFX interaction in stackpane with multiple controllers
body: <p>my Layout is:
  <a href="https://i.stack.imgur.com/xxkGa.png" rel="nofollow noreferrer">MVE</a></p>
  <p>I have trouble interacting with the controllers of other classes (yes, I know there are several threads about this - but I still don't get what's wrong ).</p>
  <p>So, basically I have a StackPane &quot;root&quot; which includes two AnchorPane's: &quot;vertMenu&quot; and &quot;content&quot;. &quot;root&quot; The StackPane is nested in a VBox for Layout purposes. &quot;vertMenu&quot; will contain different buttons to load content (from fxml-files) to the content pane - not implemented in this MVE.</p>
  <p>I want to press &quot;menuButton&quot; in class RootController to disable &quot;vertMenu&quot; from VertMenuController Class to initeract with the UI on the content pane which comes from ContentController class.</p>
  <p>My Code:</p>
  <pre><code>package application;
      
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.stage.Stage;
      
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.layout.BorderPane;
  
  
  public class Main extends Application {
      private Stage stage;
      @Override
      public void start(Stage primaryStage) {
          try {
              this.stage = primaryStage;
              FXMLLoader loader = new FXMLLoader(getClass().getResource(&quot;Root.fxml&quot;));
              Parent myPane = loader.load();
              
              Scene scene = new Scene(myPane);
              primaryStage.setScene(scene);
          
              primaryStage.show();
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
      
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  <p>Root Controller Class:</p>
  <pre><code>package application;
  
  import java.io.IOException;
  
  import javafx.animation.KeyFrame;
  import javafx.animation.KeyValue;
  import javafx.animation.Timeline;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.control.Button;
  import javafx.scene.layout.AnchorPane;
  import javafx.scene.layout.StackPane;
  import javafx.scene.layout.VBox;
  import javafx.util.Duration;
  
  public class RootController {
      @FXML private StackPane root;
      @FXML private Button menuButton;
      @FXML private Button bb;
      VertMenuController vertMenuC;
      ContentController contentC;
  
      @FXML private void initialize() {
  
      }
      
      @FXML private void menuButtonAction() throws IOException {
          FXMLLoader loader = new FXMLLoader(getClass().getResource(&quot;VertMenuView.fxml&quot;));
          Parent root = loader.load();
          vertMenuC = loader.getController();
          
          vertMenuC.disableMenu();
          
      }
      
  
  }
  </code></pre>
  <p>Root View:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  
  &lt;VBox prefHeight=&quot;450.0&quot; xmlns=&quot;http://javafx.com/javafx/8&quot; xmlns:fx=&quot;http://javafx.com/fxml/1&quot; fx:controller=&quot;application.RootController&quot;&gt;
     &lt;children&gt;
        &lt;StackPane fx:id=&quot;root&quot; maxHeight=&quot;-Infinity&quot; maxWidth=&quot;-Infinity&quot; minHeight=&quot;-Infinity&quot; minWidth=&quot;-Infinity&quot; prefHeight=&quot;400.0&quot; prefWidth=&quot;600.0&quot; style=&quot;-fx-background-color: rgb(222,222,222);&quot;&gt;
           &lt;children&gt;
              &lt;fx:include source=&quot;ContentView.fxml&quot; /&gt;
              &lt;fx:include source=&quot;VertMenuView.fxml&quot; /&gt;
           &lt;/children&gt;
        &lt;/StackPane&gt;
        &lt;Button fx:id=&quot;menuButton&quot; mnemonicParsing=&quot;false&quot; onAction=&quot;#menuButtonAction&quot; prefHeight=&quot;48.0&quot; prefWidth=&quot;157.0&quot; text=&quot;Button&quot; /&gt;
        &lt;Button fx:id=&quot;bb&quot; mnemonicParsing=&quot;false&quot; prefHeight=&quot;25.0&quot; prefWidth=&quot;154.0&quot; text=&quot;Button&quot; /&gt;
     &lt;/children&gt;
  &lt;/VBox&gt;
  </code></pre>
  <p>VertMenuController Class</p>
  <pre><code>package application;
  
  import javafx.fxml.FXML;
  import javafx.scene.control.Button;
  import javafx.scene.layout.AnchorPane;
  import javafx.scene.layout.VBox;
  
  public class VertMenuController {
      @FXML private AnchorPane vertMenu;
      @FXML private Button b1;
      @FXML private Button b2;
      @FXML private VBox vbo;
      
      
      public void disableMenu() {
          vertMenu.setDisable(true);
      }
      public void enableMenu() {
          vertMenu.setDisable(false);
      }
      
      public AnchorPane getVertMenu() {
          return vertMenu;
      }
      public VBox getBox() {
          return vbo;
      }
      
      
  }
  </code></pre>
  <p>VertMenuView</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;AnchorPane fx:id=&quot;vertMenu&quot; prefHeight=&quot;400.0&quot; prefWidth=&quot;150.0&quot; xmlns=&quot;http://javafx.com/javafx/8&quot; xmlns:fx=&quot;http://javafx.com/fxml/1&quot; fx:controller=&quot;application.VertMenuController&quot;&gt;
     &lt;children&gt;
        &lt;VBox fx:id=&quot;vbo&quot; prefHeight=&quot;400.0&quot; prefWidth=&quot;150.0&quot;&gt;
           &lt;children&gt;
              &lt;Button fx:id=&quot;b1&quot; mnemonicParsing=&quot;false&quot; prefHeight=&quot;59.0&quot; prefWidth=&quot;148.0&quot; text=&quot;B1&quot; /&gt;
              &lt;Button fx:id=&quot;b2&quot; layoutX=&quot;10.0&quot; layoutY=&quot;10.0&quot; mnemonicParsing=&quot;false&quot; prefHeight=&quot;59.0&quot; prefWidth=&quot;148.0&quot; text=&quot;B2&quot; /&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  <p>ContentController Class</p>
  <pre><code>package application;
  
  import javafx.fxml.FXML;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.layout.AnchorPane;
  
  public class ContentController {
      @FXML private AnchorPane content;
      @FXML private Button b3;
      @FXML private Label ausgabe;
      
      
      
      @FXML private void b3Action() {
          ausgabe.setText(&quot;b2 pressed&quot;);
      }
      
      public void setAusgabe() {
          this.ausgabe.setText(&quot;Hello World&quot;);
      }
      
      
  }
  </code></pre>
  <p>ContentView</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;AnchorPane fx:id=&quot;content&quot; maxWidth=&quot;600.0&quot; prefHeight=&quot;400.0&quot; prefWidth=&quot;600.0&quot; xmlns=&quot;http://javafx.com/javafx/8&quot; xmlns:fx=&quot;http://javafx.com/fxml/1&quot; fx:controller=&quot;application.ContentController&quot;&gt;
     &lt;children&gt;
        &lt;VBox prefHeight=&quot;262.0&quot; prefWidth=&quot;600.0&quot;&gt;
           &lt;children&gt;
              &lt;Button fx:id=&quot;b3&quot; mnemonicParsing=&quot;false&quot; onAction=&quot;#b3Action&quot; prefHeight=&quot;59.0&quot; prefWidth=&quot;600.0&quot; text=&quot;Button&quot; /&gt;
              &lt;Label fx:id=&quot;ausgabe&quot; prefHeight=&quot;113.0&quot; prefWidth=&quot;610.0&quot; text=&quot;Label&quot; /&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  <p>I do not get any exceptions, so I think I do correctly make a reference to the &quot;verticalMenuController&quot; in the root controller class. But unfortunately I can't disable the AnchorPane &quot;vertMenu&quot;.</p>
  <p>Thank you very much so far.</p>