因此,我正在尝试为Java / JavaFX中的GUI设计错误消息弹出窗口。对于错误消息弹出窗口,我有单独的FXML和控制器,并且我想在用户出错时调用该弹出窗口。
但是我想根据错误内容更改消息的标签文本。这就是我所拥有的:
if (carModel.isEmpty())
showError("Please enter the model of your car.");
if (carColor.isEmpty())
showError("Please enter the color of your car.");
public void showError (String text) {
Parent parentErrorMessage = FXMLLoader.load(getClass().getResource("ErrorMessage.fxml"));
Scene sceneErrorMessage = new Scene(parentErrorMessage );
Stage errorStage = new Stage();
errorStage.setScene(sceneErrorMessage);
errorStage.initModality(Modality.APPLICATION_MODAL);
errorStage.setTitle("Error");
errorStage.showAndWait();
}
所以我想根据错误发生的位置以某种方式传递一个字符串,并修改ErrorMessage.fxml中的Label。
做到这一点的最佳方法是什么?我似乎无法弄清楚。谢谢您的帮助!