如何在JOptionPane中去除问号?

3
我该如何去掉JOptionPane左上角的任何标记?
int result = JOptionPane.showConfirmDialog(null, myPanel, 
                   "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);

这个可以正常工作,但我想移除左上角的不好看的 ? 标志。

请用您自己的图标替换它。 - MadProgrammer
2个回答

6
使用PLAIN_MESSAGE消息类型。
JOptionPane.showConfirmDialog(null, "Help",
    "Please Enter X and Y Values", 
    JOptionPane.OK_CANCEL_OPTION, 
    JOptionPane.PLAIN_MESSAGE);

enter image description here


2
以下是一个被覆盖的方法showConfirmDialog():

showConfirmDialog()方法的定义如下

/**
 * Brings up a dialog where the number of choices is determined
 * by the <code>optionType</code> parameter, where the
 * <code>messageType</code>
 * parameter determines the icon to display.
 * The <code>messageType</code> parameter is primarily used to supply
 * a default icon from the Look and Feel.
 *
 * @param parentComponent determines the <code>Frame</code> in
 *                  which the dialog is displayed; if <code>null</code>,
 *                  or if the <code>parentComponent</code> has no
 *                  <code>Frame</code>, a
 *                  default <code>Frame</code> is used.
 * @param message   the <code>Object</code> to display
 * @param title     the title string for the dialog
 * @param optionType an integer designating the options available
 *                   on the dialog: <code>YES_NO_OPTION</code>,
 *                  <code>YES_NO_CANCEL_OPTION</code>,
 *                  or <code>OK_CANCEL_OPTION</code>
 * @param messageType an integer designating the kind of message this is;
 *                  primarily used to determine the icon from the pluggable
 *                  Look and Feel: <code>ERROR_MESSAGE</code>,
 *                  <code>INFORMATION_MESSAGE</code>,
 *                  <code>WARNING_MESSAGE</code>,
 *                  <code>QUESTION_MESSAGE</code>,
 *                  or <code>PLAIN_MESSAGE</code>
 * @return an integer indicating the option selected by the user
 * @exception HeadlessException if
 *   <code>GraphicsEnvironment.isHeadless</code> returns
 *   <code>true</code>
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public static int showConfirmDialog(Component parentComponent,
    Object message, String title, int optionType, int messageType)
    throws HeadlessException {
    return showConfirmDialog(parentComponent, message, title, optionType,
                            messageType, null);
}

如你所见,第五个参数是int messageType,您可以设置它。

有各种消息类型可供选择,例如:

  1. ERROR_MESSAGE(错误消息)
  2. INFORMATION_MESSAGE(信息消息)
  3. WARNING_MESSAGE(警告消息)
  4. QUESTION_MESSAGE(询问消息)
  5. PLAIN_MESSAGE(普通消息)

您可以选择符合您需求的一种消息类型。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接