title: Java FX change label in previous stage
body: <p>I have pretty simple application (i just want to understand controller switching mechanism). First window shows label and button. When you click the button, another window with button will show. Now when you click this second button, Label in first window should change. I have read some posts here, also tried this one <a href="https://stackoverflow.com/questions/40959672/java-fx-change-label-text-in-a-previous-stage-scene">Java FX change Label text in a previous stage scene</a>, however, with no success. If you could explain it to me on this simple example, maybe i will be able to better understand controllers logic. Here is my code, thank for any help:</p>
  
  <p>PrimaryController with label to be changed and the button, which opens new window</p>
  
  <pre><code>public class PrimaryController implements Initializable {
  
  @FXML
  private Label label;
  
  @FXML
  private Button btnButton;
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
      btnButton.setOnAction((event) -&gt; {
  
          try {
              FXMLLoader loader = new FXMLLoader(getClass().getResource("secondaryFXML.fxml"));
              Parent root = loader.load();
              loader.&lt;SecondaryController&gt;getController().setPrimaryController(this);
              Stage stage = new Stage();
              Scene scene = new Scene(root);
  
              stage.setScene(scene);
              stage.show();
          } catch (IOException ex) {
              Logger.getLogger(PrimaryController.class.getName()).log(Level.SEVERE, null, ex);
          }
      });        
  }    
  
  public void setLabelText(String string){
      label.setText(string);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Secondary Controller with change label button</p>
  
  <pre><code>public class SecondaryController implements Initializable {
  
  @FXML
  private Button btnChangeLabel;
  
  private PrimaryController primary;
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
  
      btnChangeLabel.setOnAction((event) -&gt; {            
          try {
              FXMLLoader loader = new FXMLLoader(getClass().getResource("primaryFXML.fxml"));
              loader.load();
              PrimaryController primaryCtrl = loader.&lt;PrimaryController&gt;getController();
              primaryCtrl.setLabelText("eres");
  
          } catch (IOException ex) {
              Logger.getLogger(SecondaryController.class.getName()).log(Level.SEVERE, null, ex);
          }
      });
  }
  
  public void setPrimaryController(PrimaryController primary){
      this.primary = primary;
  }
  </code></pre>
  
  <p>}</p>