I am new in JavaFX and fail in what I need to do: I change scene this way and at the same time define an event filter:
AnchorPane pane = FXMLLoader.load(getClass().getResource("blabla.fxml"));
Scene scene = new Scene(pane);
scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
public void handle(KeyEvent event) {
System.out.println("Filtering event " + event.getEventType() + ", " + event.getCode());
//Here in the handle method I want to call a method of the current controller
}
});
Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
appStage.setScene(scene);
appStage.show();
In the handle method of the event filter I want to execute a particular method of the loaded controller (change images). I cannot put a setOnKeyPressed in this controller since the associated fxml has only images key pressed are not catched. I read that I had to use the addEventFilter on the scene. It works. The handle method is correctly triggered but I do not know how to access a method on the controller associated to "blabla.fxml".
Many many thanks for your help.
Dominique