1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
當(dāng)您調(diào)用時(shí)不應(yīng)創(chuàng)建控制器,F(xiàn)XMLLoader.load因?yàn)閘oad將創(chuàng)建控制器。您也不應(yīng)該使用 load 的靜態(tài)版本。你的代碼應(yīng)該看起來像這樣:
public static ControllerClass display(String title, String message) throws IOException {
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader();
Parent root= loader.load(getClass().getResource("/Alertbox.fxml"));
ControllerClass controller = loader.getController();
controller.lblResult.setText("message");
stage.setTitle(title);
stage.setScene(new Scene(root));
stage.show();
return controller;
}
這可能仍然不完全正確,但它應(yīng)該為您指明正確的方向。
注意,ControllerClass 是控制器的類名。
添加回答
舉報(bào)