title: JavaFx Controller: detect when stage is closing
body: <p>I have a javaFx project and I would like to implement a method <strong>inside the Controller</strong> that is invoked every time the stage(window) is closing this to be able to perform some actions before closing it. 
  The desire to have the method placed inside the controller is because the actions to be taken depend on the choices that the user has made while using the scene.</p>
  
  <p>My goal is every time the user closes the stage, to have a print and then an user related action.</p>
  
  <p>I try inside the controller class:</p>
  
  <pre><code>@FXML
      public void exitApplication(ActionEvent event) {
          System.out.println("stop");
          action();
          Platform.exit();
      }
  </code></pre>
  
  <p>but it's no effective.</p>