美好的一天!
我正在使用 JavaFX SDK 开发程序。我想要像 C# 中那样的消息框:
DialogResult rs = MessageBox.showDialog("Message Here...");
if (rs == ....) {
// code
}
我想使用 JavaFX SDK 实现这样的功能。非常感谢您的回答。
最佳答案
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Alert.html
The Alert class subclasses the Dialog class, and provides support for a number of pre-built dialog types that can be easily shown to users to prompt for a response.
所以代码看起来像
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Message Here...");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you!");
alert.showAndWait().ifPresent(rs -> {
if (rs == ButtonType.OK) {
System.out.println("Pressed OK.");
}
});
关于JavaFX 2.1 消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11662857/