특정 대화 상자를 만드는 일반적인 방법을 만들고 싶습니다.Javafx로 일반 Dialog 메서드 만들기
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"
입니까? 고맙습니다.
나는별로 경험이 없습니다. 즉, 당신이 정말 간단한 캐스팅보다 더 형태 보증하지
loader.<MyController>getController().setDialogStage(dialogStage);
을 할 수