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.