title: JavaFX - How to use a method in a controller from another controller?
body: <p>Working with SceneBuilder. I have 2 stages, each one with a controller:<br/> <code>stage1Controller</code>,<br/><code>stage2Controller</code>.<br/>
  <strong>Stage1Controller :</strong></p>
  
  <pre><code>public class Stage1Controller {
      @FXML
      private MenuItem translate;
      @FXML
      private Menu file;
      @FXML
      private Menu edit;
      @FXML
      private Menu help;
  
  
      @FXML 
      private void handleTranslate (ActionEvent event){
          translateFirstStage();
          //HOW TO ACCESS THE stage2Controller setLabel()??
      }
  
      private void translateFirstStage(){
          file.setText("Fichier");
          edit.setText("Modifier");
          help.setText("Aide");
      }
  }
  </code></pre>
  
  <p><strong>Stage2Controller:</strong></p>
  
  <pre><code>public class Stage2Controller {
      @FXML
      private Label lb;
  
  
      private void setLabel(String string){
          lb.setText("string");
      }
  }
  </code></pre>
  
  <p>Here is how both fxml files are loaded in Main.java class using 2 methods <br/> (called in <code>Start(Stage primaryStage)</code> method): </p>
  
  <pre><code>public void firstStage() {
          try {
              // Load root layout from fxml file.
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(Main.class.getResource("view/stage1.fxml"));
              rootLayout = (BorderPane) loader.load();
  
              // Show the scene containing the root layout.
              Scene scene = new Scene(rootLayout);
              primaryStage.setScene(scene);
              primaryStage.show();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      public void secondStage() {
  
          try {
              // Load root layout from fxml file.
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(Main.class.getResource("view/stage2.fxml"));
              XD = (AnchorPane) loader.load();
  
              // Show the scene containing the root layout.
              Scene scene = new Scene(XD);
              Stage stage = new Stage();
              stage.setScene(scene);
              stage.show();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <ul>
  <li>The <code>handleTranslate(ActionEvent event)</code> method is used as an <code>OnAction</code> method for the <code>MenuItem translate</code> in the first Stage, it translates the view in both stages. <br/></li>
  </ul>
  
  <p><strong>How Can i put <code>setLabel</code> in <code>handleTranslate</code> Method ? Thanks</strong></p>