有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有没有办法自定义输入对话框上的按钮?

我正在尝试创建一个输入对话框,其中有自定义的按钮。我试图创建一个带有自定义按钮的showOptionDialog,但后来我无法将文本区域放置在输入对话框中。我该怎么做

以下是我使用的代码:

Object[] buttons = { "Submit", "Cancel" };
jtxf = new JTextField(15);
JOptionPane.showOptionDialog(null, "Enter a Student ID", "Student ID",
                             JOptionPane.YES_NO_OPTION,
                             JOptionPane.QUESTION_MESSAGE, null, buttons,
                             buttons[0]);

共 (1) 个答案

  1. # 1 楼答案

    查看this tutorial。你可以阅读整个页面,但链接直接指向自定义按钮部分

    或者您也可以使用showInputDialog,如下所示:

    String s = (String)JOptionPane.showInputDialog(
                this,
                "Complete the sentence:\n"
                        + "\"Green eggs and...\"",
                "Customized Dialog",
                JOptionPane.PLAIN_MESSAGE,
                null,
                null,
                "enter text here");