my imageI'm trying to pass the data (variables) from one stage to another stage, but when I try to access them in the second stage they are null. Code of the mainWindow. Go to window1
public class PrincipalController {
private Stage primaryStage;
public void initStage( Stage stage){ primaryStage = stage;}
@FXML
private void goWindow1(ActionEvent event) {
try {
FXMLLoader miCargador = new
FXMLLoader(getClass().getResource("/vista/Window1.fxml"));
Parent root = (Parent) miCargador.load();
// Access to window driver 1
Window1Controller window1 = miCargador.
<window1Controlador>getController();
windnow1.initStage(primaryStage);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {e.printStackTrace();}
}
}
// window1 class:
public class Window1Controlador {
private Stage primaryStage;
private Scene escenaAnterior;
private String tituloAnterior;
public void initStage(Stage stage){
primaryStage = stage;
escenaAnterior = stage.getScene();
tituloAnterior = stage.getTitle();
primaryStage.setTitle("Window 1");
}
If I want to access previous title that I received comes null
/**
* Initializes the controller class.
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println(""+ this.tituloAnterior);}
The initialize shows me null when it should show me "Window1" }