|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object charvax.swing.JOptionPane
JOptionPane makes it easy to pop up a standard dialog box that prompts the user for information or displays some information.
The labels of the option-buttons displayed within the popup dialog can be customized by changing static variables in the JOptionPane class. Similarly, "accelerator keys" can be set to have the same effect as the option-buttons. For example, the following code would set the label of the OK button to "OK (F1)", and set the F1 key to have the same effect as the OK button:
JOptionPane.OK_LABEL = "OK (F1)"; JOptionPane.OK_ACCELERATOR = KeyEvent.VK_F1;
Note that after the buttons have been customized, they stay customized for all future invocations of the JOptionPane "showXXXDialog()" methods.
The parameters to these methods follow consistent patterns:
- parentComponent
- Defines the Component that is to be the parent of this dialog box. It is used in two ways: its screen coordinates are used in the placement of the dialog box, and the dialog box inherits its foreground and background colors from
parentComponent
(unless the the JOptionPane's colors have been set explicitly). In general, the dialog box centered on top ofparentComponent
. This parameter may be null, in which case a default Frame is used as the parent, and the dialog will be centered on the screen.
- message
- A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type:
- String
- The string is displayed as a message on one line.
- Object[]
- An array of Objects is interpreted as a series of messages arranged in a vertical stack. Each Object is converted to a String using its toString() method. The result is wrapped in a JLabel and displayed.
- messageType
- Defines the style of the message. The possible values are:
ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_MESSAGE
- optionType
- Defines the set of option buttons that appear at the bottom of the dialog box:
You aren't limited to this set of option buttons. You can provide any buttons you want using the
DEFAULT_OPTION
YES_NO_OPTION
YES_NO_CANCEL_OPTION
OK_CANCEL_OPTION
options
parameter.
- options
- A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on its type:
- Component
- The component is added to the button row directly.
- other
- The Object is converted to a string using its toString method and the result is used to label a JButton.
- icon
- This parameter is used in javax.Swing to specify a decorative icon to be placed in the dialog box. It is ignored by Charva.
- title
- The title for the dialog box.
- initialValue
- The default selection (input value).
Field Summary | |
protected java.lang.Object |
_initialValue
Option that should be initially selected in _options . |
protected java.lang.String |
_inputValue
|
protected java.lang.Object |
_message
|
protected int |
_messagetype
|
protected java.lang.Object[] |
_options
Array of options to display to the user in the bottom button-panel. |
protected int |
_optiontype
Determines which option buttons to display (unless an array of options is explicitly specified with setOptions() ). |
protected java.lang.Object |
_value
The currently selected option. |
protected boolean |
_wantsInput
If true, an TextField will be displayed for the user to provide input. |
static int |
CANCEL_ACCELERATOR
|
static java.lang.String |
CANCEL_LABEL
|
static int |
CANCEL_OPTION
|
static int |
CLOSED_OPTION
|
static int |
DEFAULT_OPTION
|
static int |
ERROR_MESSAGE
|
static int |
INFORMATION_MESSAGE
|
static int |
NO_ACCELERATOR
|
static java.lang.String |
NO_LABEL
|
static int |
NO_OPTION
|
static int |
OK_ACCELERATOR
|
static int |
OK_CANCEL_OPTION
|
static java.lang.String |
OK_LABEL
|
static int |
OK_OPTION
|
static int |
PLAIN_MESSAGE
|
static int |
QUESTION_MESSAGE
|
static int |
WARNING_MESSAGE
|
static int |
YES_ACCELERATOR
|
static java.lang.String |
YES_LABEL
|
static int |
YES_NO_CANCEL_OPTION
|
static int |
YES_NO_OPTION
|
static int |
YES_OPTION
|
Constructor Summary | |
JOptionPane()
Creates a JOptionPane with a test message |
|
JOptionPane(java.lang.Object message_)
Creates an instance of JOptionPane to display the specified message. |
|
JOptionPane(java.lang.Object message_,
int messagetype_)
Creates an instance of JOptionPane to display the specified message. |
|
JOptionPane(java.lang.Object message_,
int messagetype_,
int optiontype_)
Creates an instance of JOptionPane to display the specified message. |
|
JOptionPane(java.lang.Object message_,
int messageType_,
int optionType_,
java.lang.Object icon_,
java.lang.Object[] options_,
java.lang.Object initialValue_)
Creates an instance of JOptionPane to display the specified message. |
Method Summary | |
JDialog |
createDialog(Component owner_,
java.lang.String title_)
Creates and returns a new JDialog for displaying the required message. |
java.lang.Object |
getInitialValue()
Returns the initial value that is to be enabled -- the Component that has the focus when the pane is initially displayed. |
java.lang.Object |
getInputValue()
Returns the value the user has input, (relevant only if _wantsInput is true). |
java.lang.Object[] |
getOptions()
Returns the choices the user can make. |
java.lang.Object |
getValue()
Returns the option the user has selected. |
boolean |
getWantsInput()
Returns the value of _wantsInput. |
void |
setInitialSelectionValue(java.lang.Object value_)
Sets the default input value that is displayed to the user. |
void |
setInitialValue(java.lang.Object initialValue_)
Sets the initial value that is to be enabled -- the Component that has the focus when the pane is initially displayed. |
void |
setInputValue(java.lang.Object value_)
Sets the initial value of the text field for the user to modify. |
void |
setOptions(java.lang.Object[] newOptions_)
Sets the options this pane displays in the button-panel at the bottom. |
void |
setWantsInput(boolean newvalue_)
If newvalue_ is true, a JTextField will be displayed for the user to provide text input. |
static int |
showConfirmDialog(Component parent_,
java.lang.Object message_,
java.lang.String title_,
int optiontype_)
Brings up a dialog where the number of choices is dependent on the value of the optiontype_ parameter. |
static java.lang.String |
showInputDialog(Component parent_,
java.lang.Object message_,
java.lang.String title_,
int messagetype_)
Brings up a dialog that allows the user to input a value. |
static void |
showMessageDialog(Component parent_,
java.lang.Object message_)
Brings up a confirmation dialog titled "Confirm" |
static void |
showMessageDialog(Component parent_,
java.lang.Object message_,
java.lang.String title_,
int msgtype_)
Brings up a confirmation dialog with the specified title. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Object _message
protected int _messagetype
protected int _optiontype
setOptions()
).
protected boolean _wantsInput
protected java.lang.String _inputValue
protected java.lang.Object[] _options
protected java.lang.Object _initialValue
_options
.
protected java.lang.Object _value
public static final int ERROR_MESSAGE
public static final int INFORMATION_MESSAGE
public static final int WARNING_MESSAGE
public static final int QUESTION_MESSAGE
public static final int PLAIN_MESSAGE
public static final int DEFAULT_OPTION
public static final int YES_NO_OPTION
public static final int YES_NO_CANCEL_OPTION
public static final int OK_CANCEL_OPTION
public static final int YES_OPTION
public static final int NO_OPTION
public static final int CANCEL_OPTION
public static final int OK_OPTION
public static final int CLOSED_OPTION
public static java.lang.String YES_LABEL
public static java.lang.String NO_LABEL
public static java.lang.String CANCEL_LABEL
public static java.lang.String OK_LABEL
public static int YES_ACCELERATOR
public static int NO_ACCELERATOR
public static int CANCEL_ACCELERATOR
public static int OK_ACCELERATOR
Constructor Detail |
public JOptionPane()
public JOptionPane(java.lang.Object message_)
message_
- the message to display. It can be a String
or an array of Strings. If it is an array of Strings, they are
stacked vertically.public JOptionPane(java.lang.Object message_, int messagetype_)
message_
- the message to display. It can be a String
or an array of Strings.messagetype_
- is ignored. It is used in javax.swing to
determine which icon to display.public JOptionPane(java.lang.Object message_, int messagetype_, int optiontype_)
message_
- the message to display. It can be a String
or an array of Strings.messagetype_
- is ignored. It is used in javax.swing to
determine which icon to display.optiontype_
- determines which option-buttons to display. Allowed
values are: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, and
OK_CANCEL_OPTION.public JOptionPane(java.lang.Object message_, int messageType_, int optionType_, java.lang.Object icon_, java.lang.Object[] options_, java.lang.Object initialValue_)
message_
- the message to display. It can be a String
or an array of Strings.messageType_
- is ignored. It is used in javax.swing to
determine which icon to display.optionType_
- determines which option-buttons to display. Allowed
values are: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, and
OK_CANCEL_OPTION.icon_
- the Icon image to display (not used by Charva; it is here
for compatibility with Swing).options_
- the choices the user can selectinitialValue_
- the choice that is initially selected; if null,
then nothing will be initially selected; only meaningful if "options"
is usedMethod Detail |
public void setWantsInput(boolean newvalue_)
public boolean getWantsInput()
public void setInitialSelectionValue(java.lang.Object value_)
_wantsInput
is true.
public void setInputValue(java.lang.Object value_)
public java.lang.Object getInputValue()
public void setOptions(java.lang.Object[] newOptions_)
public java.lang.Object[] getOptions()
public void setInitialValue(java.lang.Object initialValue_)
public java.lang.Object getInitialValue()
public JDialog createDialog(Component owner_, java.lang.String title_)
owner_
component and is centered on it.
If owner_
is null, default (black/white) colors are used.
public static int showConfirmDialog(Component parent_, java.lang.Object message_, java.lang.String title_, int optiontype_)
parent_
- Determines the frame in which the dialog is displayed.message_
- the String to display.title_
- the title of the dialog.optiontype_
- must be YES_NO_OPTION or YES_NO_CANCEL_OPTION.public static java.lang.String showInputDialog(Component parent_, java.lang.Object message_, java.lang.String title_, int messagetype_)
parent_
- Determines the frame in which the dialog is displayed.message_
- the String to display.title_
- the title of the dialog.messagetype_
- is ignored (it is used in javax.swing to determine
which icon to display).public static void showMessageDialog(Component parent_, java.lang.Object message_)
public static void showMessageDialog(Component parent_, java.lang.Object message_, java.lang.String title_, int msgtype_)
public java.lang.Object getValue()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |