Java Reference
In-Depth Information
If the message is an array of objects ( Object[ ] ), make the JOptionPane place each entry
onto a separate row.
If the message is a Component , place the component in the message area.
If the message is an Icon , place the Icon within a JLabel and display the label in the
message area.
If the message is an Object , convert it to a String with toString() , place the String in a
JLabel , and display the label in the message area.
The JOptionPane Message Type and Icon Arguments
The messageType constructor argument is used to represent the type of message being displayed
within the JOptionPane . If you don't provide a custom icon for the JOptionPane , the installed
look and feel will use the messageType argument setting to determine which icon to display
within the icon area. Five different message types are available as JOptionPane constants:
ERROR_MESSAGE for displaying an error message
INFORMATION_MESSAGE for displaying an informational message
QUESTION_MESSAGE for displaying a query message
WARNING_MESSAGE for displaying a warning message
PLAIN_MESSAGE for displaying any other type of message
If you're using a constructor with both messageType and icon arguments and want the
JOptionPane to use the default icon for the messageType , just specify null as the value for the
icon argument. If the icon argument is non- null , the specified icon will be used, no matter
what the message type is.
If the messageType constructor argument isn't specified, the default message type is
PLAIN_MESSAGE .
The JOptionPane Option Type Argument
The optionType constructor argument is used to determine the configuration for the set of
buttons in the button area. If one of the options argument described next is provided, then the
optionType argument is ignored and configuration for the set of buttons is acquired from the
options argument. Four different option types are available as JOptionPane constants:
DEFAULT_OPTION for a single OK button
OK_CANCEL_OPTION for OK and Cancel buttons
YES_NO_CANCEL_OPTION for Yes, No, and Cancel buttons
YES_NO_OPTION for Yes and No buttons
If the optionType constructor argument isn't specified, the default option type is
DEFAULT_OPTION .
Search WWH ::




Custom Search