我想創建一個通用的方法來創建一個特定的對話框。用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();
}
}
但我在這行
loader.getController().setDialogStage(dialogStage)
得到一個錯誤,完全錯誤是這個
"The method setDialogStage(Stage) is undefined for the type Object"
我該如何解決?謝謝。
我不是很有經驗。 ,指出