Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改JavaFX8警报对话框中是/否按钮的文本_Java_Javafx_Dialog - Fatal编程技术网

如何更改JavaFX8警报对话框中是/否按钮的文本

如何更改JavaFX8警报对话框中是/否按钮的文本,java,javafx,dialog,Java,Javafx,Dialog,我有以下代码片段: Alert alert = new Alert(AlertType.WARNING, "The format for dates is year.month.day. " + "For example, today is " + todayToString() + ".", ButtonType.OK, ButtonType.CANCEL); alert.

我有以下代码片段:

Alert alert = 
        new Alert(AlertType.WARNING, 
            "The format for dates is year.month.day. " +
            "For example, today is " + todayToString() + ".",
             ButtonType.OK, 
             ButtonType.CANCEL);
alert.setTitle("Date format warning");
Optional<ButtonType> result = alert.showAndWait();

if (result.get() == ButtonType.OK) {
    formatGotIt = true;
}
警报=
新警报(AlertType.WARNING,
“日期的格式为year.month.day。”+
例如,今天是“+todayToString()+”,
好的,
按钮类型。取消);
alert.setTitle(“日期格式警告”);
可选结果=alert.showAndWait();
if(result.get()==ButtonType.OK){
formatgottit=true;
}

在上面,我请求两个标题为“是”和“否”的按钮。但是,我希望更改这两个按钮。

您可以定义自己的按钮类型。在此示例中,按钮的文本为
foo
bar

ButtonType foo = new ButtonType("foo", ButtonBar.ButtonData.OK_DONE);
ButtonType bar = new ButtonType("bar", ButtonBar.ButtonData.CANCEL_CLOSE);
Alert alert = new Alert(AlertType.WARNING,
        "The format for dates is year.month.day. "
        + "For example, today is " + todayToString() + ".",
        foo,
        bar);

alert.setTitle("Date format warning");
Optional<ButtonType> result = alert.showAndWait();

if (result.orElse(bar) == foo) {
    formatGotIt = true;
}
buttonype foo=新的按钮类型(“foo”,ButtonBar.ButtonData.OK\u DONE);
按钮类型栏=新按钮类型(“栏”,按钮栏。按钮数据。取消\关闭);
警报警报=新警报(AlertType.WARNING,
“日期的格式为year.month.day。”
+例如,今天是“+todayToString()+”,
福,
酒吧);
alert.setTitle(“日期格式警告”);
可选结果=alert.showAndWait();
如果(结果orElse(bar)=foo){
formatgottit=true;
}

事实上,我发现这可能对某些人有用。特别是在JavaFx对话框类警报的情况下。示例:Alert errorAlert=新警报(Alert.AlertType.ERROR);它非常相关,解决了我的问题。请记住,“dialog”也可能是一个“Alert”对象。
((Button) dialog.getDialogPane().lookupButton(ButtonType.OK)).setText("Not OK Anymore");
((Button) dialog.getDialogPane().lookupButton(ButtonType.CANCEL)).setText("Not Cancel Anymore");