0

I have read this post about Passing Parameters JavaFX FXML. What I want to know is. Is it possible to pass an object without reinitializing the window? Ideally, I would like to have a popup window where the user enters their login information. Then when they press the login button, the login window goes away and the login info is passed back to the main window.

Community
  • 1
  • 1
Cody Cook
  • 3
  • 8
  • I don't really understand what you mean by "without reinitializing the window". – James_D Jun 21 '16 at 18:58
  • I was confused. I though in the answer on the post I linked he was closing the main window and reopening it with the added data. As this is way the guy in this video did it https://www.youtube.com/watch?v=Vh7XDjWlm_w. – Cody Cook Jun 21 '16 at 19:23
  • Yeah, the youtube you linked is nonsense, imho. – James_D Jun 21 '16 at 19:45

1 Answers1

1

Display the popup with showAndWait(), which will block execution until the window is dismissed. Then you can just call a method (that you define) on the controller to retrieve the data you need. Something like:

FXMLLoader loader = new FXMLLoader(...);
Scene scene = new Scene(loader.load());
Stage loginPopup = new Stage();
loginPopup.setScene(scene);
LoginController loginController = loader.getController();
loginPopup.showAndWait();
MyLoginData data = loginController.getLoginData();
// process data...
James_D
  • 201,275
  • 16
  • 291
  • 322