Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove question mark in a JOptionPane?

How can I get rid of any marks at the left top corner of a JOptionPane?

int result = JOptionPane.showConfirmDialog(null, myPanel, 
                   "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);

This works fine, but I want to remove the nasty ? at the left top corner.

like image 807
Buras Avatar asked Nov 18 '25 13:11

Buras


2 Answers

Use the PLAIN_MESSAGE message type

JOptionPane.showConfirmDialog(null, "Help",
    "Please Enter X and Y Values", 
    JOptionPane.OK_CANCEL_OPTION, 
    JOptionPane.PLAIN_MESSAGE);

enter image description here

like image 92
MadProgrammer Avatar answered Nov 21 '25 01:11

MadProgrammer


There is an overridden method showConfirmDialog() as follows

/**
 * 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);
}

As you can see the 5th parameter is the int messageType which you can set. There are various message types like

  1. ERROR_MESSAGE
  2. INFORMATION_MESSAGE
  3. WARNING_MESSAGE
  4. QUESTION_MESSAGE
  5. PLAIN_MESSAGE

You can select the one that meets your requirement.

like image 30
Aniket Thakur Avatar answered Nov 21 '25 02:11

Aniket Thakur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!