我尝试使用带有控件FX的代码创建Dialog:
// Show the error message.
Dialogs.create()
.title("Invalid Fields")
.masthead("Please correct invalid fields")
.message(errorMessage)
.showError();
但不行。后来我读到控件FX无法与Java FX 2.X一起使用,所以我发现javafx.scene.control.Alert
所以我使用了这段代码:
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you!");
alert.showAndWait();
但仍然无法正常工作。我尝试手动导入javafx.scene.control.*
并抛出错误:
Caused by: java.lang.Error: Unresolved compilation problems:
Alert cannot be resolved to a type
Alert cannot be resolved to a type
AlertType cannot be resolved to a variable
我做错了什么?我该如何显示对话/警告信息?
问候。