title: JavaFX - Many Static FXML Controllers
body: <p>A <code>JavaFX</code> application exists and the application is starting from the <code>Main.class</code> file which <code>extends Application</code>:</p>
  
  <pre><code>  public class Main extends Application {
  
      /**
       * Keep a reference to the main Stage
       */
      public static Stage                 stage;
      /**
       * MainScene Controller
       */
      public static MainScene             mainSceneController;
      /**
       * The Capture Window of the application
       */
      public static CaptureWindow         captureWindowController;
      /**
       * Settings Scene Controller
       */
      public static SettingsController    settingsController;
  
      @Override
      public void start(Stage primary) throws Exception {
  
          stage = primary;
          ..........
  
          // CaptureWindow
          FXMLLoader loader1 = new FXMLLoader(getClass().getResource("/fxml/CaptureWindow.fxml"));
          loader1.load();
          captureWindowController = loader1.getController();
  
          // MainScene
          mainSceneController = new MainScene();
  
          .........   
      }
  
    }
  </code></pre>
  
  <hr>
  
  <p><strong>Description</strong></p>
  
  <p>As you can see above I have 3 <code>FXMLControllers</code>(one is reusable[<code>extends StackPane</code>],others not).I have declared all of them <strong>static</strong> cause i want to access variables from one <code>FXMLController</code> from the other <code>FXMLControllers</code>.I use this strategy every time I use <code>JavaFX</code> and I don't think is good...</p>
  
  <p>How I can change the code below so I can access variables or methods of one <code>FXMLController</code> from other <code>FXMLController</code>? Is that possible without using <code>static</code> keyword?</p>
  
  <p>Consider that the Controllers are represented from different classes which can be in different packages.</p>
  
  <hr>
  
  <p>Also before writing this question I had a look <a href="https://stackoverflow.com/questions/21502430/static-fxml-variables-in-fxml-controller">Static @FXML variables in FXML Controller</a></p>