如何在JavaFX 8 Alert中指定按钮的特定顺序 [英] How to specify a particular order of buttons in a JavaFX 8 Alert

查看:359
本文介绍了如何在JavaFX 8 Alert中指定按钮的特定顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要请用户确认是否已执行操作。确认对话框的按钮集为是,否和取消。我的代码如下:

I need to ask the user to confirm doing an action. The set of buttons of the confirmation dialog are "Yes", "No" and "Cancel". My code is below:

private ButtonType askYesNoCancel(String question) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setContentText(question);
    alert.getButtonTypes().setAll(ButtonType.YES, 
                                  ButtonType.NO, 
                                  ButtonType.CANCEL);
    return alert.showAndWait().get();
}

这给了我

我面临的问题是,无论我以什么顺序指定 ButtonType 警报,我得到相同的按钮顺序(否-取消-是)。我看了 Alert Button ButtonType ,可惜,没有找到答案。

The problem I am facing is that regardless in what order I specify the ButtonTypes for an Alert, I get the same button order (No - Cancel - Yes). I took a look at API documentation for Alert, Button and ButtonType, alas, not to find an answer.

我想要实现的是按钮顺序,是-否-取消。有任何建议吗?

What I try to accomplish, is the button order Yes - No - Cancel. Any advice?

推荐答案

检查答案:输入键事件在Javafx中的对话框上不起作用?,尽管我猜答案更恰当地属于此问题,并且可能无法完全解释所发生的情况。另请阅读 ButtonBar Javadoc

Check the answer to: Enter Key Event Is Not Working On Dialog In Javafx?, though I guess that answer more appropriately belongs with this question and perhaps doesn't fully explain what is going on. Also read the ButtonBar javadoc.

基本上,按钮位置由 ButtonType 和ButtonBar的 buttonOrder 。通过更改这两项,您最终将获得不同的按钮布局。

Basically, the button position is determined by a combination of the ButtonType of each button and the ButtonBar's buttonOrder. By changing either of these things, you will end up with different button layouts.

我记得,自定义ButtonBar有点棘手。您可能需要对警报进行子类化并覆盖 createButtonBar

As I recall, customizing the ButtonBar was kind of tricky. You might need to subclass the alert and override createButtonBar.


我想要完成的是按钮顺序是-否-取消。有什么建议吗?

What I try to accomplish, is the button order Yes - No - Cancel. Any advice?

我的建议是:不要尝试自定义按钮顺序,而要应用系统默认顺序。按钮顺序已经预先配置为与各种操作系统对话框的标准按钮布局相匹配。重新排列按钮的顺序以偏离该标准可能会使您的应用程序对用户造成混乱(尽管这是一个非常主观的意见)。

My advice is: Don't try to customize the button order, but let the system default order be applied. The button order has already been preconfigured to match the standard button layout for dialogs for various operating systems. Reordering the buttons to deviate from that standard may make your application just slightly more confusing for users (that's a pretty subjective opinion though).

这篇关于如何在JavaFX 8 Alert中指定按钮的特定顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆