11

我想将“是”和“否”更改为“同意/不同意”之类的内容。我应该怎么办?

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

5 回答 5

30

您可以执行以下操作

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

输出如下

在此处输入图像描述

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

于 2013-08-17T07:10:07.607 回答
7

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

Object[] options = { "Agree", "Disagree" };
JOptionPane.showOptionDialog(null, "These are my terms", "Terms",
    JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, 
    options, options[0]);
于 2013-08-17T07:03:20.347 回答
4

试试这个:

请参阅JOptionPane 文档

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]);
于 2013-08-17T07:01:51.317 回答
3

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

于 2013-08-17T06:56:58.653 回答
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;
        }
于 2014-04-18T07:16:20.650 回答