Java 如何在确认对话框中更改是/否选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18286027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:04:25  来源:igfitidea点击:

How to change Yes/No option in confirmation dialog?

javaswingjbuttonjoptionpane

提问by Kashama Shinn

I want to change YES and NO to something like Agree/Disagree. What should I do?

我想将“是”和“否”更改为“同意/不同意”。我该怎么办?

int reply = JOptionPane.showConfirmDialog(null,
                                          "Are you want to continue the process?",
                                          "YES?",
                                          JOptionPane.YES_NO_OPTION);

回答by Joban Dhillon

You might want to checkout JOptionPane.showOptionDialog, that will let you push in a text parameter (in array form).

您可能想要 checkout JOptionPane.showOptionDialog,这将让您推送文本参数(以数组形式)。

回答by Maxim Shoustin

Try this one:

试试这个:

See JOptionPane documentation

请参阅JOptionPane 文档

JOptionPane(Object message, int messageType, int optionType,
        Icon icon, Object[] options, Object initialValue)

where options specifies the buttons with initialValue. So you can change them

其中 options 指定带有初始值的按钮。所以你可以改变它们

Example

例子

Object[] options = { "Agree", "Disagree" };

JOptionPane.showOptionDialog(null, "Are you want to continue the process?", "information",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, options, options[0]);

回答by Joachim Isaksson

You can use the optionsparameter to push custom options to showOptionDialog;

您可以使用该options参数将自定义选项推送到showOptionDialog

Object[] options = { "Agree", "Disagree" };
JOptionPane.showOptionDialog(null, "These are my terms", "Terms",
    JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, 
    options, options[0]);

回答by Aniket Thakur

You can do the following

您可以执行以下操作

JFrame frame = new JFrame();
String[] options = new String[2];
options[0] = new String("Agree");
options[1] = new String("Disagree");
JOptionPane.showOptionDialog(frame.getContentPane(),"Message!","Title", 0,JOptionPane.INFORMATION_MESSAGE,null,options,null);

output is as follows

输出如下

enter image description here

在此处输入图片说明

For more details about the showOptionDialog() function see here.

有关 showOptionDialog() 函数的更多详细信息,请参见此处

回答by sathya

Try This!!

尝试这个!!

int res = JOptionPane.showConfirmDialog(null, "Are you want to continue the process?", "", JOptionPane.YES_NO_OPTION);
        switch (res) {
            case JOptionPane.YES_OPTION:
            JOptionPane.showMessageDialog(null, "Process Successfully");
            break;
            case JOptionPane.NO_OPTION:
            JOptionPane.showMessageDialog(null, "Process is Canceled");
            break;
        }