gpt4 book ai didi

java - 如何更改 JavaFX 8 警报对话框中是/否按钮的文本

转载 作者:行者123 更新时间:2023-12-03 12:06:12 24 4
gpt4 key购买 nike

我有这个代码片段:

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;
}

在上面,我请求了两个标题为"is"和“否”的按钮。但是,我想改变它们。

最佳答案

您可以定义自己的按钮类型。在这个例子中,按钮的文本是 foobar :

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;
}

关于java - 如何更改 JavaFX 8 警报对话框中是/否按钮的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36309385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com