0

Hi I'm new in JavaFX and I'm working on my first app so I don't understand some mechanisms very well. I'm using SceneBuilder. I have 3 fxml files for 3 scenes and one FXMLcontoller for them. I have first window with button which take you to another window and it works. But i also need by clicking that button to set values of that new window's elements but it seems that it does not work , as I thought ..

Here is code of that button in controller. labelToChange is element of second window included in window2.fxml.

@FXML
private void handle_toNextWindow_btn(ActionEvent event) throws IOException {

        Stage stage;
        Parent root;
        stage = (Stage) toNextWindow_btn.getScene().getWindow();
        root = FXMLLoader.load(getClass().getResource("window2.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
        labelToChange.setText("Some text"); //this doesn't work
}

Thanks for answers and sorry for bad english.

skypjack
  • 49,335
  • 19
  • 95
  • 187
Lacreon
  • 9
  • 3
  • Problem not described. More details needed as to what is the issue – dbmitch Jun 26 '16 at 17:05
  • "I have 3 fxml files for 3 scenes and one FXMLcontoller for them." No: a new controller is created every time you load an FXML file, by default, and your code snippet shows you haven't changed that. You might be using the same controller class, so all the controllers are instances of the same class, but they are not the "same controller" (and it's a really bad idea to make them all the same class: use a different controller *class* for each FXML file). – James_D Jun 27 '16 at 00:48

0 Answers0