title: JavaFX Stage close event handler
body: <p>I have a Stage in JavaFX that can be closed in multiple ways, either by clicking the red (X) or by a Button which calls <code>stage.close()</code></p>
  
  <p>Regardless of how the Stage is closed, I would like to perform an action before (or as) it is closed.</p>
  
  <p>If I use the following code:</p>
  
  <pre><code>myStage.setOnCloseRequest( event -&gt; {System.out.println("Closing Stage");} );
  </code></pre>
  
  <p>then the handler is called when I click the (X) but not when I call <code>myStage.close()</code></p>
  
  <p>This is the same issue that this question talks about (with a key difference):
  <a href="https://stackoverflow.com/questions/26619566/javafx-stage-close-handler">JavaFX: Stage close handler</a></p>
  
  <p>The difference is that he wants to call a handler as the entire application is closed, and therefore can override the <code>Application</code>'s <code>stop()</code> method.  However I'm not closing the entire application, just one stage.  And <code>Stage</code> does not have a <code>stop()</code> method to override.</p>
  
  <p>Thanks for any help.</p>