Je voudrais créer une méthode générique pour créer une boîte de dialogue spécifique.Créer une méthode de dialogue générique avec Javafx
private void setDialog(String dialog,String title){
try {
// Load the fxml file and create a new stage for the popup
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/view/" + dialog + ".fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle(title);
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(Main.getPs());
Scene scene = new Scene(page);
dialogStage.setScene(scene);
loader.getController().setDialogStage(dialogStage);
// Show the dialog and wait until the user closes it
dialogStage.showAndWait();
} catch (IOException e) {
// Exception gets thrown if the fxml file could not be loaded
e.printStackTrace();
}
}
Mais je reçois une erreur dans cette ligne
loader.getController().setDialogStage(dialogStage)
exactement l'erreur est ce
"The method setDialogStage(Stage) is undefined for the type Object"
comment puis-je résoudre ce problème? Je vous remercie.
Je ne suis pas très expérimenté. qui dit que