RobertoTroiano
RobertoTroiano

Reputation: 21

Return value from stage

In javaFX i open a new stage by this code:

    Parent root2 ;
    root2 = FXMLLoader.load(getClass().getResource("FXMLelencoSoci.fxml"));
    Scene scena = new Scene(root2, 800, 800);
    final Stage stage2 = new Stage();
    stage2.initStyle(StageStyle.UNDECORATED);
    stage2.initModality(Modality.WINDOW_MODAL);
    stage2.initOwner(((Node) event.getSource()).getScene().getWindow());
    stage2.setScene(scena);
    stage2.show();

this display a table with 2 colums code(int) and name(string) How can i obtain from the caller Stage the value of the code selected in the table? Thanks

Upvotes: 0

Views: 3493

Answers (2)

RobertoTroiano
RobertoTroiano

Reputation: 21

I create a class with a static int variabile set closing stage2 and read at the end of showAndWait method of stage1

Upvotes: 0

Magcus
Magcus

Reputation: 866

here is a solution... posibly not the best one... You could use the UserData of the root2. from the controller of the FXMLelencoSoci, set the user data to the main pane of it. This you can achive it by doing the followin:

mainPane.setUserData(value);

and from the main stage, you know this pane as root2, so use this:

value = root2.getUserData();

That would be the way that you want... But I would make the two controllers know each other, so that you can still use the Tiped references.

Upvotes: 2

Related Questions