charvax.swing
Class JOptionPane

java.lang.Object
  extended bycharvax.swing.JOptionPane

public class JOptionPane
extends java.lang.Object

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 of parentComponent. 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:
  • DEFAULT_OPTION
  • YES_NO_OPTION
  • YES_NO_CANCEL_OPTION
  • OK_CANCEL_OPTION
You aren't limited to this set of option buttons. You can provide any buttons you want using the 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

_message

protected java.lang.Object _message

_messagetype

protected int _messagetype

_optiontype

protected int _optiontype
Determines which option buttons to display (unless an array of options is explicitly specified with setOptions()).


_wantsInput

protected boolean _wantsInput
If true, an TextField will be displayed for the user to provide input.


_inputValue

protected java.lang.String _inputValue

_options

protected java.lang.Object[] _options
Array of options to display to the user in the bottom button-panel. The objects in this array can be any combination of Strings or components which are subclasses of AbstractButton. Buttons are just added to the bottom button-panel; Strings are wrapped in a JButton which is then added to the button-panel.


_initialValue

protected java.lang.Object _initialValue
Option that should be initially selected in _options.


_value

protected java.lang.Object _value
The currently selected option.


ERROR_MESSAGE

public static final int ERROR_MESSAGE
See Also:
Constant Field Values

INFORMATION_MESSAGE

public static final int INFORMATION_MESSAGE
See Also:
Constant Field Values

WARNING_MESSAGE

public static final int WARNING_MESSAGE
See Also:
Constant Field Values

QUESTION_MESSAGE

public static final int QUESTION_MESSAGE
See Also:
Constant Field Values

PLAIN_MESSAGE

public static final int PLAIN_MESSAGE
See Also:
Constant Field Values

DEFAULT_OPTION

public static final int DEFAULT_OPTION
See Also:
Constant Field Values

YES_NO_OPTION

public static final int YES_NO_OPTION
See Also:
Constant Field Values

YES_NO_CANCEL_OPTION

public static final int YES_NO_CANCEL_OPTION
See Also:
Constant Field Values

OK_CANCEL_OPTION

public static final int OK_CANCEL_OPTION
See Also:
Constant Field Values

YES_OPTION

public static final int YES_OPTION
See Also:
Constant Field Values

NO_OPTION

public static final int NO_OPTION
See Also:
Constant Field Values

CANCEL_OPTION

public static final int CANCEL_OPTION
See Also:
Constant Field Values

OK_OPTION

public static final int OK_OPTION
See Also:
Constant Field Values

CLOSED_OPTION

public static final int CLOSED_OPTION
See Also:
Constant Field Values

YES_LABEL

public static java.lang.String YES_LABEL

NO_LABEL

public static java.lang.String NO_LABEL

CANCEL_LABEL

public static java.lang.String CANCEL_LABEL

OK_LABEL

public static java.lang.String OK_LABEL

YES_ACCELERATOR

public static int YES_ACCELERATOR

NO_ACCELERATOR

public static int NO_ACCELERATOR

CANCEL_ACCELERATOR

public static int CANCEL_ACCELERATOR

OK_ACCELERATOR

public static int OK_ACCELERATOR
Constructor Detail

JOptionPane

public JOptionPane()
Creates a JOptionPane with a test message


JOptionPane

public JOptionPane(java.lang.Object message_)
Creates an instance of JOptionPane to display the specified message.

Parameters:
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.

JOptionPane

public JOptionPane(java.lang.Object message_,
                   int messagetype_)
Creates an instance of JOptionPane to display the specified message.

Parameters:
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.

JOptionPane

public JOptionPane(java.lang.Object message_,
                   int messagetype_,
                   int optiontype_)
Creates an instance of JOptionPane to display the specified message.

Parameters:
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.

JOptionPane

public 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.

Parameters:
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 select
initialValue_ - the choice that is initially selected; if null, then nothing will be initially selected; only meaningful if "options" is used
Method Detail

setWantsInput

public void setWantsInput(boolean newvalue_)
If newvalue_ is true, a JTextField will be displayed for the user to provide text input.


getWantsInput

public boolean getWantsInput()
Returns the value of _wantsInput.


setInitialSelectionValue

public void setInitialSelectionValue(java.lang.Object value_)
Sets the default input value that is displayed to the user. Only used if _wantsInput is true.


setInputValue

public void setInputValue(java.lang.Object value_)
Sets the initial value of the text field for the user to modify.


getInputValue

public java.lang.Object getInputValue()
Returns the value the user has input, (relevant only if _wantsInput is true).


setOptions

public void setOptions(java.lang.Object[] newOptions_)
Sets the options this pane displays in the button-panel at the bottom. If an element in newOptions is an instance of a subclass of AbstractButton (for example, a JButton), it is added directly to the pane, otherwise a button is created for the element. The advantage of adding a button rather than a string is that a mnemonic can be set for the button.


getOptions

public java.lang.Object[] getOptions()
Returns the choices the user can make.


setInitialValue

public 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. (NOT IMPLEMENTED YET).


getInitialValue

public 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. (NOT IMPLEMENTED YET).


createDialog

public JDialog createDialog(Component owner_,
                            java.lang.String title_)
Creates and returns a new JDialog for displaying the required message. The dialog inherits the foreground and background colors of the owner_ component and is centered on it. If owner_ is null, default (black/white) colors are used.


showConfirmDialog

public 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.

Parameters:
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.

showInputDialog

public 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.

Parameters:
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).

showMessageDialog

public static void showMessageDialog(Component parent_,
                                     java.lang.Object message_)
Brings up a confirmation dialog titled "Confirm"


showMessageDialog

public static void showMessageDialog(Component parent_,
                                     java.lang.Object message_,
                                     java.lang.String title_,
                                     int msgtype_)
Brings up a confirmation dialog with the specified title. The msgtype parameter is ignored (it is used in the javax.swing package to specify an icon to display).


getValue

public java.lang.Object getValue()
Returns the option the user has selected.