public static int showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)
throws HeadlessExceptionBrings up a dialog with a specified icon, where the initial
choice is determined by the initialValue parameter and
the number of choices is determined by the optionType
parameter.
If optionType is YES_NO_OPTION,
or YES_NO_CANCEL_OPTION
and the options parameter is null,
then the options are
supplied by the look and feel.
The messageType parameter is primarily used to supply
a default icon from the look and feel.Parameters:parentComponent - determines the Frame
in which the dialog is displayed; if
null, or if the
parentComponent has no
Frame, a
default Frame is usedmessage - the Object to displaytitle - the title string for the dialogoptionType - an integer designating the options available on the
dialog: YES_NO_OPTION,
or YES_NO_CANCEL_OPTIONmessageType - an integer designating the kind of message this is,
primarily used to determine the icon from the
pluggable Look and Feel: ERROR_MESSAGE,
INFORMATION_MESSAGE,
WARNING_MESSAGE,
QUESTION_MESSAGE,
or PLAIN_MESSAGEicon - the icon to display in the dialogoptions - an array of objects indicating the possible choices
the user can make; if the objects are components, they
are rendered properly; non-String
objects are
rendered using their toString methods;
if this parameter is null,
the options are determined by the Look and FeelinitialValue - the object that represents the default selection
for the dialog; only meaningful if options
is used; can be null
Returns:an integer indicating the option chosen by the user,
or CLOSED_OPTION if the user closed
the dialog
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)
throws HeadlessExceptionBrings up a dialog with a specified icon, where the initial
choice is determined by the initialValue parameter and
the number of choices is determined by the optionType
parameter.
If optionType is YES_NO_OPTION,
or YES_NO_CANCEL_OPTION
and the options parameter is null,
then the options are
supplied by the look and feel.
The messageType parameter is primarily used to supply
a default icon from the look and feel.Parameters:parentComponent - determines the Frame
in which the dialog is displayed; if
null, or if the
parentComponent has no
Frame, a
default Frame is usedmessage - the Object to displaytitle - the title string for the dialogoptionType - an integer designating the options available on the
dialog: YES_NO_OPTION,
or YES_NO_CANCEL_OPTIONmessageType - an integer designating the kind of message this is,
primarily used to determine the icon from the
pluggable Look and Feel: ERROR_MESSAGE,
INFORMATION_MESSAGE,
WARNING_MESSAGE,
QUESTION_MESSAGE,
or PLAIN_MESSAGEicon - the icon to display in the dialogoptions - an array of objects indicating the possible choices
the user can make; if the objects are components, they
are rendered properly; non-String
objects are
rendered using their toString methods;
if this parameter is null,
the options are determined by the Look and FeelinitialValue - the object that represents the default selection
for the dialog; only meaningful if options
is used; can be null
Returns:an integer indicating the option chosen by the user,
or CLOSED_OPTION if the user closed
the dialog
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,null, options, options[1]);showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)对着参数来看!parentComponent 定义当前对话框的父组件,通常情况为null。Object message 提示给用户的文字String title 对话框的titleint optionType 定义对话框上的按钮表现形式,在这些值里面来选一个:DEFAULT_OPTION
YES_NO_OPTION
YES_NO_CANCEL_OPTION
OK_CANCEL_OPTION int messageType 定义对话框的消息类型,在这些值里面来选一个:ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_MESSAGE
Icon icon,图标选项,有则设定,没有则为nullObject[] options,用户自定义选项,见例子。Object initialValue,设定默认值,见例子。
呵呵,我八婆一下,补充:message不一定仅仅是文字。是Object类型。也可以是一些可视组件。如JPanel,Label,List之类的。可以使界面更生色一些。通常简单的使用是String。