title: How to wait in Java FX controller for return value from window?
body: <p>I have an java fx controller class having do method, where I wish to wait till I collect information from another screen. See below code to understand better. This do() method is called from my Javafx Application class's start() method.</p>
  
  <pre><code>@FXML
  public void do() throws Exception {
  
      FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("/fxml/myPage.fxml"));
      Parent root = (Parent)fxmlLoader.load();
      Scene mainScene = new Scene(root);
      Stage stage = new Stage();  
      stage.setHeight(500);
      stage.setWidth(400);
      stage.setScene(mainScene);
      stage.setTitle("Provide input");        
      stage.show();       
      System.out.println(Thread.currentThread().getName() +"returned");
  }
  </code></pre>
  
  <p>So here I am calling do method from my Application and wish that do() return me value that I capture from myPage screen.  Here I don't find anyway to wait. If I put wait after call to show(), screen is never displayed. JavaFX expect that I return from this function and then only I see screen and I also see "Returned" message on console. </p>
  
  <p>I can write another method which controller of this new page will call after fetching input but then I am anyway returning from my do() method. How can I stay here only?  I tried to open new Thread and then load fxml but it gives "Not Same Thread" error.  I see that even start() method of javaFX Application class need to get control back to show the screen.</p>