I'm currently recoding a small application from Swing to JavaFX, since it seemed like the easiest way to deploy what I currently have for web.
I can't seem to do something very simple, and I'm getting lost on the documentation and other posts:
Anyway, I have my main controller that calls the associated FXML file:
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
Now, from Login.fxml, I have a button and I want that button to open another FXML file. I can get the button to be sucesfully load the event but I tried many things and I can't get it to work. I'm trying something like this:
private void handleButtonAction(ActionEvent event){
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("GeneradorBases.fxml"));
// fxmlLoader.setRoot(this);
// fxmlLoader.setController(this);
try {
fxmlLoader.load();
}
catch (IOException e){
throw new RuntimeException(e);
}
}
I tried to follow an example I saw here on Stackoverflow. Basically the .setRoot and .setController crash the application. Even the .load() does that too.
Any advice on how I can make this work?