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

时间:2013-08-17 06:53:36

标签: java swing jbutton joptionpane

我想将YES和NO改为同意/不同意。 我该怎么办?

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

5 个答案:

答案 0 :(得分:23)

您可以执行以下操作

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

输出如下

enter image description here

有关showOptionDialog()函数的更多详细信息,请参阅here

答案 1 :(得分:5)

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

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

答案 2 :(得分:3)

您可能需要结帐JOptionPane.showOptionDialog,这样您就可以推送文本参数(以数组形式)。

答案 3 :(得分:3)

试试这个:

请参阅JOptionPane documentation

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

其中options指定具有initialValue的按钮。所以你可以改变它们

示例

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]);

答案 4 :(得分:2)

试试这个!!

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