小编典典

如何在JavaFX 2.0中创建和显示常见对话框(错误,警告,确认)?

javascript

如何在JavaFX 2.0中创建和显示常见对话框(错误,警告,确认)?我找不到任何“标准”类,如DialogDialogBoxMessage或什么的。


阅读 393

收藏
2020-09-26

共1个答案

小编典典

最近发布的JDK 1.8.0_40添加了对JavaFX对话框,警报等的支持。例如,要显示确认对话框,可以使用Alert类:

Alert alert = new Alert(AlertType.CONFIRMATION, "Delete " + selection + " ?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
alert.showAndWait();

if (alert.getResult() == ButtonType.YES) {
    //do stuff
}

以下是此版本中添加的类的列表:

javafx.scene.control.Dialog
javafx.scene.control.Alert
javafx.scene.control.TextInputDialog
javafx.scene.control.ChoiceDialog

2020-09-26