JavaFX 2.1 消息框

标签 java javafx javafx-2

美好的一天!
我正在使用 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/

相关文章:

JavaFX - SetText() to TextArea 在程序完成之前不会执行

JavaFX 访问 Controller 给出空指针异常

java - Android GPS 位置追踪器

java - 创建 Hadoop 序列文件

JavaFX - Stage 参数的重点是什么?

java - InvalidModuleDescriptorException : Package hellofx. org.openjfx 在模块中找不到

JavaFX : IllegalArgumentException when mouse is clicked any where on scene

3d - JavaFX 3D 图形 : Mouse click position on 3D object

java - Spring:在加载之前检查类路径资源是否存在

java - 字典序链表返回空指针异常