javax.swing

Class JOptionPane

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class JOptionPane
extends JComponent
implements Accessible

This class creates different types of JDialogs and JInternalFrames that can ask users for input or pass on information. JOptionPane can be used by calling one of the show static methods or by creating an instance of JOptionPane and calling createDialog or createInternalFrame.
See Also:
Serialized Form

Nested Class Summary

protected class
JOptionPane.AccessibleJOptionPane
Provides the accessibility features for the JOptionPane component.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

Nested classes/interfaces inherited from class java.awt.Container

Container.AccessibleAWTContainer

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static int
CANCEL_OPTION
The value returned when cancel option is selected.
static int
CLOSED_OPTION
The value returned when the dialog is closed without a selection.
static int
DEFAULT_OPTION
An option used in confirmation dialog methods.
static int
ERROR_MESSAGE
Identifier for the error message type.
static String
ICON_PROPERTY
The identifier for the propertyChangeEvent when the icon property changes.
static int
INFORMATION_MESSAGE
Identifier for the information message type.
static String
INITIAL_SELECTION_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the initialSelectionValue property changes.
static String
INITIAL_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the initialValue property changes.
static String
INPUT_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the inputValue property changes.
static String
MESSAGE_PROPERTY
The identifier for the propertyChangeEvent when the message property changes.
static String
MESSAGE_TYPE_PROPERTY
The identifier for the propertyChangeEvent when the messageType property changes.
static int
NO_OPTION
The value returned when the no option is selected.
static int
OK_CANCEL_OPTION
An option used in confirmation dialog methods.
static int
OK_OPTION
The value returned when the ok option is selected.
static String
OPTIONS_PROPERTY
The identifier for the propertyChangeEvent when the options property changes.
static String
OPTION_TYPE_PROPERTY
The identifier for the propertyChangeEvent when the optionType property changes.
static int
PLAIN_MESSAGE
Identifier for the plain message type.
static int
QUESTION_MESSAGE
Identifier for the question message type.
static String
SELECTION_VALUES_PROPERTY
The identifier for the propertyChangeEvent when the selectionValues property changes.
static Object
UNINITIALIZED_VALUE
The value returned when the inputValue is uninitialized.
static String
VALUE_PROPERTY
The identifier for the propertyChangeEvent when the value property changes.
static String
WANTS_INPUT_PROPERTY
The identifier for the propertyChangeEvent when the wantsInput property changes.
static int
WARNING_MESSAGE
Identifier for the warning message type.
static int
YES_NO_CANCEL_OPTION
An option used in confirmation dialog methods.
static int
YES_NO_OPTION
An option used in confirmation dialog methods.
static int
YES_OPTION
The value returned when the yes option is selected.
protected Icon
icon
The icon displayed in the dialog/internal frame.
protected Object
initialSelectionValue
The initial selected value in the input component.
protected Object
initialValue
The object that is initially selected for options.
protected Object
inputValue
The value the user inputs.
protected Object
message
The message displayed in the dialog/internal frame.
protected int
messageType
The type of message displayed.
protected int
optionType
The type of options to display.
protected Object[]
options
The options (usually buttons) aligned at the bottom for the user to select.
protected Object[]
selectionValues
The input values the user can select.
protected Object
value
The value returned by selecting an option.
protected boolean
wantsInput
Whether the Dialog/InternalFrame needs input.

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

JOptionPane()
Creates a new JOptionPane object using a message of "JOptionPane message", using the PLAIN_MESSAGE type and DEFAULT_OPTION.
JOptionPane(Object message)
Creates a new JOptionPane object using the given message using the PLAIN_MESSAGE type and DEFAULT_OPTION.
JOptionPane(Object message, int messageType)
Creates a new JOptionPane object using the given message and messageType and DEFAULT_OPTION.
JOptionPane(Object message, int messageType, int optionType)
Creates a new JOptionPane object using the given message, messageType and optionType.
JOptionPane(Object message, int messageType, int optionType, Icon icon)
Creates a new JOptionPane object using the given message, messageType, optionType and icon.
JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
Creates a new JOptionPane object using the given message, messageType, optionType, icon and options.
JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue)
Creates a new JOptionPane object using the given message, messageType, optionType, icon, options and initialValue.

Method Summary

JDialog
createDialog(Component parentComponent, String title)
This method creates a new JDialog that is either centered around the parent's frame or centered on the screen (if the parent is null).
JInternalFrame
createInternalFrame(Component parentComponent, String title)
This method creates a new JInternalFrame that is in the JLayeredPane which contains the parentComponent given.
AccessibleContext
getAccessibleContext()
Returns the object that provides accessibility features for this JOptionPane component.
static JDesktopPane
getDesktopPaneForComponent(Component parentComponent)
This method returns the JDesktopPane for the given parentComponent or null if none can be found.
static Frame
getFrameForComponent(Component parentComponent)
This method returns the Frame for the given parentComponent or null if none can be found.
Icon
getIcon()
This method returns the icon displayed.
Object
getInitialSelectionValue()
This method returns the value initially selected from the list of values the user can input.
Object
getInitialValue()
This method returns the value that is focused from the list of options.
Object
getInputValue()
This method returns the value that the user input.
int
getMaxCharactersPerLineCount()
This method returns the maximum characters per line.
Object
getMessage()
This method returns the message displayed.
int
getMessageType()
This method returns the message type.
int
getOptionType()
This method returns the option type.
Object[]
getOptions()
This method returns the options.
static Frame
getRootFrame()
This method returns the Frame used by JOptionPane dialog's that have no parent.
Object[]
getSelectionValues()
This method returns the selection values.
OptionPaneUI
getUI()
This method returns the UI used by the JOptionPane.
String
getUIClassID()
This method returns an identifier to determine which UI class will act as the UI.
Object
getValue()
This method returns the value that the user selected out of options.
boolean
getWantsInput()
This method returns whether this JOptionPane wants input.
protected String
paramString()
This method returns a String that describes this JOptionPane.
void
selectInitialValue()
This method requests focus for the initial value.
void
setIcon(Icon newIcon)
This method changes the icon property.
void
setInitialSelectionValue(Object newValue)
This method changes the initial selection property.
void
setInitialValue(Object newValue)
This method changes the initial value property.
void
setInputValue(Object newValue)
This method changes the inputValue property.
void
setMessage(Object newMessage)
This method changes the message property.
void
setMessageType(int newType)
This method changes the messageType property.
void
setOptionType(int newType)
This method changes the optionType property.
void
setOptions(Object[] newOptions)
This method changes the options property.
static void
setRootFrame(Frame newRootFrame)
This method changes the Frame used for JOptionPane dialogs that have no parent.
void
setSelectionValues(Object[] newValues)
This method changes the selectionValues property.
void
setUI(OptionPaneUI ui)
This method sets the UI used with the JOptionPane.
void
setValue(Object newValue)
This method sets the value has been selected out of options.
void
setWantsInput(boolean newValue)
This method changes the wantsInput property.
static int
showConfirmDialog(Component parentComponent, Object message)
This method shows a confirmation dialog with the title "Select an Option" and displays the given message.
static int
showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
This method shows a confirmation dialog with the given message, optionType and title.
static int
showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType)
This method shows a confirmation dialog with the given message, title, messageType and optionType.
static int
showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon)
This method shows a confirmation dialog with the given message, title, optionType, messageType and icon.
static String
showInputDialog(Component parentComponent, Object message)
This method will show a QUESTION_MESSAGE input dialog with the given message.
static String
showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
This method will show a QUESTION_MESSAGE type input dialog with the given message and initialSelectionValue.
static String
showInputDialog(Component parentComponent, Object message, String title, int messageType)
This method displays a new input dialog with the given message, title and messageType.
static Object
showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
This method shows an input dialog with the given message, title, messageType, icon, selectionValues, and initialSelectionValue.
static String
showInputDialog(Object message)
This method shows a QUESTION_MESSAGE type input dialog.
static String
showInputDialog(Object message, Object initialSelectionValue)
This method shows a QUESTION_MESSAGE type input dialog.
static int
showInternalConfirmDialog(Component parentComponent, Object message)
This method shows an internal confirmation dialog with the given message.
static int
showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType)
This method shows an internal confirmation dialog with the given message, optionType and title.
static int
showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType)
This method shows an internal confirmation dialog with the given message, title, optionTypes and icon for the given message type.
static int
showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon)
This method shows an internal confirmation dialog with the given message, title, option type, message type, and icon.
static String
showInternalInputDialog(Component parentComponent, Object message)
This method shows an internal input dialog with the given message.
static String
showInternalInputDialog(Component parentComponent, Object message, String title, int messageType)
This method shows an internal input dialog with the given message, title and message type.
static Object
showInternalInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
This method shows an internal input dialog with the given message, title message type, icon, selection value list and initial selection value.
static void
showInternalMessageDialog(Component parentComponent, Object message)
This method shows an internal message dialog with the given message.
static void
showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType)
This method shows an internal message dialog with the given message, title and message type.
static void
showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
This method shows an internal message dialog with the given message, title, message type and icon.
static int
showInternalOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
This method displays an internal option dialog with the given message, title, option type, message type, icon, option list, and initial option value.
static void
showMessageDialog(Component parentComponent, Object message)
This method shows an INFORMATION_MESSAGE type message dialog.
static void
showMessageDialog(Component parentComponent, Object message, String title, int messageType)
This method shows a message dialog with the given message, title and messageType.
static void
showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
This method shows a message dialog with the given message, title, messageType and icon.
static int
showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
This method shows an option dialog with the given message, title, optionType, messageType, icon, options and initialValue.
void
updateUI()
This method resets the UI to the Look and Feel default.

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

CANCEL_OPTION

public static final int CANCEL_OPTION
The value returned when cancel option is selected.
Field Value:
2

CLOSED_OPTION

public static final int CLOSED_OPTION
The value returned when the dialog is closed without a selection.
Field Value:
-1

DEFAULT_OPTION

public static final int DEFAULT_OPTION
An option used in confirmation dialog methods.
Field Value:
-1

ERROR_MESSAGE

public static final int ERROR_MESSAGE
Identifier for the error message type.
Field Value:
0

ICON_PROPERTY

public static final String ICON_PROPERTY
The identifier for the propertyChangeEvent when the icon property changes.
Field Value:
"icon"

INFORMATION_MESSAGE

public static final int INFORMATION_MESSAGE
Identifier for the information message type.
Field Value:
1

INITIAL_SELECTION_VALUE_PROPERTY

public static final String INITIAL_SELECTION_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the initialSelectionValue property changes.
Field Value:
"initialSelectionValue"

INITIAL_VALUE_PROPERTY

public static final String INITIAL_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the initialValue property changes.
Field Value:
"initialValue"

INPUT_VALUE_PROPERTY

public static final String INPUT_VALUE_PROPERTY
The identifier for the propertyChangeEvent when the inputValue property changes.
Field Value:
"inputValue"

MESSAGE_PROPERTY

public static final String MESSAGE_PROPERTY
The identifier for the propertyChangeEvent when the message property changes.
Field Value:
"message"

MESSAGE_TYPE_PROPERTY

public static final String MESSAGE_TYPE_PROPERTY
The identifier for the propertyChangeEvent when the messageType property changes.
Field Value:
"messageType"

NO_OPTION

public static final int NO_OPTION
The value returned when the no option is selected.
Field Value:
1

OK_CANCEL_OPTION

public static final int OK_CANCEL_OPTION
An option used in confirmation dialog methods.
Field Value:
2

OK_OPTION

public static final int OK_OPTION
The value returned when the ok option is selected.
Field Value:
0

OPTIONS_PROPERTY

public static final String OPTIONS_PROPERTY
The identifier for the propertyChangeEvent when the options property changes.
Field Value:
"options"

OPTION_TYPE_PROPERTY

public static final String OPTION_TYPE_PROPERTY
The identifier for the propertyChangeEvent when the optionType property changes.
Field Value:
"optionType"

PLAIN_MESSAGE

public static final int PLAIN_MESSAGE
Identifier for the plain message type.
Field Value:
-1

QUESTION_MESSAGE

public static final int QUESTION_MESSAGE
Identifier for the question message type.
Field Value:
3

SELECTION_VALUES_PROPERTY

public static final String SELECTION_VALUES_PROPERTY
The identifier for the propertyChangeEvent when the selectionValues property changes.
Field Value:
"selectionValues"

UNINITIALIZED_VALUE

public static final Object UNINITIALIZED_VALUE
The value returned when the inputValue is uninitialized.

VALUE_PROPERTY

public static final String VALUE_PROPERTY
The identifier for the propertyChangeEvent when the value property changes.
Field Value:
"value"

WANTS_INPUT_PROPERTY

public static final String WANTS_INPUT_PROPERTY
The identifier for the propertyChangeEvent when the wantsInput property changes.
Field Value:
"wantsInput"

WARNING_MESSAGE

public static final int WARNING_MESSAGE
Identifier for the warning message type.
Field Value:
2

YES_NO_CANCEL_OPTION

public static final int YES_NO_CANCEL_OPTION
An option used in confirmation dialog methods.
Field Value:
1

YES_NO_OPTION

public static final int YES_NO_OPTION
An option used in confirmation dialog methods.
Field Value:
0

YES_OPTION

public static final int YES_OPTION
The value returned when the yes option is selected.
Field Value:
0

icon

protected Icon icon
The icon displayed in the dialog/internal frame.

initialSelectionValue

protected Object initialSelectionValue
The initial selected value in the input component.

initialValue

protected Object initialValue
The object that is initially selected for options.

inputValue

protected Object inputValue
The value the user inputs.

message

protected Object message
The message displayed in the dialog/internal frame.

messageType

protected int messageType
The type of message displayed.

optionType

protected int optionType
The type of options to display.

options

protected Object[] options
The options (usually buttons) aligned at the bottom for the user to select.

selectionValues

protected Object[] selectionValues
The input values the user can select.

value

protected Object value
The value returned by selecting an option.

wantsInput

protected boolean wantsInput
Whether the Dialog/InternalFrame needs input.

Constructor Details

JOptionPane

public JOptionPane()
Creates a new JOptionPane object using a message of "JOptionPane message", using the PLAIN_MESSAGE type and DEFAULT_OPTION.

JOptionPane

public JOptionPane(Object message)
Creates a new JOptionPane object using the given message using the PLAIN_MESSAGE type and DEFAULT_OPTION.
Parameters:
message - The message to display.

JOptionPane

public JOptionPane(Object message,
                   int messageType)
Creates a new JOptionPane object using the given message and messageType and DEFAULT_OPTION.
Parameters:
message - The message to display.
messageType - The type of message.

JOptionPane

public JOptionPane(Object message,
                   int messageType,
                   int optionType)
Creates a new JOptionPane object using the given message, messageType and optionType.
Parameters:
message - The message to display.
messageType - The type of message.
optionType - The type of options.

JOptionPane

public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon)
Creates a new JOptionPane object using the given message, messageType, optionType and icon.
Parameters:
message - The message to display.
messageType - The type of message.
optionType - The type of options.
icon - The icon to display.

JOptionPane

public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon,
                   Object[] options)
Creates a new JOptionPane object using the given message, messageType, optionType, icon and options.
Parameters:
message - The message to display.
messageType - The type of message.
optionType - The type of options.
icon - The icon to display.
options - The options given.

JOptionPane

public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon,
                   Object[] options,
                   Object initialValue)
Creates a new JOptionPane object using the given message, messageType, optionType, icon, options and initialValue. The initialValue will be focused initially.
Parameters:
message - The message to display.
messageType - The type of message.
optionType - The type of options.
icon - The icon to display.
options - The options given.
initialValue - The component to focus on initially.
Throws:
IllegalArgumentException - If the messageType or optionType are not legal values.

Method Details

createDialog

public JDialog createDialog(Component parentComponent,
                            String title)
This method creates a new JDialog that is either centered around the parent's frame or centered on the screen (if the parent is null). The JDialog will not be resizable and will be modal. Once the JDialog is disposed, the inputValue and value properties will be set by the optionPane.
Parameters:
parentComponent - The parent of the Dialog.
title - The title in the bar of the JDialog.
Returns:
A new JDialog based on the JOptionPane configuration.

createInternalFrame

public JInternalFrame createInternalFrame(Component parentComponent,
                                          String title)
            throws RuntimeException
This method creates a new JInternalFrame that is in the JLayeredPane which contains the parentComponent given. If no suitable JLayeredPane can be found from the parentComponent given, a RuntimeException will be thrown.
Parameters:
parentComponent - The parent to find a JDesktopPane from.
title - The title of the JInternalFrame.
Returns:
A new JInternalFrame based on the JOptionPane configuration.
Throws:
RuntimeException - If no suitable JDesktopPane is found.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JOptionPane component.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JComponent
Returns:
The accessible context (an instance of JOptionPane.AccessibleJOptionPane).

getDesktopPaneForComponent

public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
This method returns the JDesktopPane for the given parentComponent or null if none can be found.
Parameters:
parentComponent - The component to look in.
Returns:
The JDesktopPane for the given component or null if none can be found.

getFrameForComponent

public static Frame getFrameForComponent(Component parentComponent)
This method returns the Frame for the given parentComponent or null if none can be found.
Parameters:
parentComponent - The component to look in.
Returns:
The Frame for the given component or null if none can be found.

getIcon

public Icon getIcon()
This method returns the icon displayed.
Returns:
The icon displayed.

getInitialSelectionValue

public Object getInitialSelectionValue()
This method returns the value initially selected from the list of values the user can input.
Returns:
The initial selection value.

getInitialValue

public Object getInitialValue()
This method returns the value that is focused from the list of options.
Returns:
The initial value from options.

getInputValue

public Object getInputValue()
This method returns the value that the user input.
Returns:
The user's input value.

getMaxCharactersPerLineCount

public int getMaxCharactersPerLineCount()
This method returns the maximum characters per line. By default, this is Integer.MAX_VALUE.
Returns:
The maximum characters per line.

getMessage

public Object getMessage()
This method returns the message displayed.
Returns:
The message displayed.

getMessageType

public int getMessageType()
This method returns the message type.
Returns:
The message type.

getOptionType

public int getOptionType()
This method returns the option type.
Returns:
The option type.

getOptions

public Object[] getOptions()
This method returns the options.
Returns:
The options.

getRootFrame

public static Frame getRootFrame()
This method returns the Frame used by JOptionPane dialog's that have no parent.
Returns:
The Frame used by dialogs that have no parent.

getSelectionValues

public Object[] getSelectionValues()
This method returns the selection values.
Returns:
The selection values.

getUI

public OptionPaneUI getUI()
This method returns the UI used by the JOptionPane.
Returns:
The UI used by the JOptionPane.

getUIClassID

public String getUIClassID()
This method returns an identifier to determine which UI class will act as the UI.
Overrides:
getUIClassID in interface JComponent
Returns:
The UI identifier.

getValue

public Object getValue()
This method returns the value that the user selected out of options.
Returns:
The value that the user selected out of options.

getWantsInput

public boolean getWantsInput()
This method returns whether this JOptionPane wants input.
Returns:
Whether this JOptionPane wants input.

paramString

protected String paramString()
This method returns a String that describes this JOptionPane.
Overrides:
paramString in interface JComponent
Returns:
A String that describes this JOptionPane.

selectInitialValue

public void selectInitialValue()
This method requests focus for the initial value.

setIcon

public void setIcon(Icon newIcon)
This method changes the icon property.
Parameters:
newIcon - The new icon to use.

setInitialSelectionValue

public void setInitialSelectionValue(Object newValue)
This method changes the initial selection property.
Parameters:
newValue - The new initial selection.

setInitialValue

public void setInitialValue(Object newValue)
This method changes the initial value property.
Parameters:
newValue - The new initial value.

setInputValue

public void setInputValue(Object newValue)
This method changes the inputValue property.
Parameters:
newValue - The new inputValue.

setMessage

public void setMessage(Object newMessage)
This method changes the message property.
Parameters:
newMessage - The new message.

setMessageType

public void setMessageType(int newType)
This method changes the messageType property.
Parameters:
newType - The new messageType.
Throws:
IllegalArgumentException - If the messageType is not valid.

setOptionType

public void setOptionType(int newType)
This method changes the optionType property.
Parameters:
newType - The new optionType.
Throws:
IllegalArgumentException - If the optionType is not valid.

setOptions

public void setOptions(Object[] newOptions)
This method changes the options property.
Parameters:
newOptions - The new options.

setRootFrame

public static void setRootFrame(Frame newRootFrame)
This method changes the Frame used for JOptionPane dialogs that have no parent.
Parameters:
newRootFrame - The Frame to use for dialogs that have no parent.

setSelectionValues

public void setSelectionValues(Object[] newValues)
This method changes the selectionValues property.
Parameters:
newValues - The new selectionValues.

setUI

public void setUI(OptionPaneUI ui)
This method sets the UI used with the JOptionPane.
Parameters:
ui - The UI used with the JOptionPane.

setValue

public void setValue(Object newValue)
This method sets the value has been selected out of options.
Parameters:
newValue - The value that has been selected out of options.

setWantsInput

public void setWantsInput(boolean newValue)
This method changes the wantsInput property.
Parameters:
newValue - Whether this JOptionPane requires input.

showConfirmDialog

public static int showConfirmDialog(Component parentComponent,
                                    Object message)
This method shows a confirmation dialog with the title "Select an Option" and displays the given message. The parent frame will be the same as the parent frame of the given parentComponent. This method returns the option chosen by the user.
Parameters:
parentComponent - The parentComponent to find a frame in.
message - The message to display.
Returns:
The option that was selected.

showConfirmDialog

public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType)
This method shows a confirmation dialog with the given message, optionType and title. The frame that owns the dialog will be the same frame that holds the given parentComponent. This method returns the option that was chosen.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
optionType - The optionType.
Returns:
The option that was chosen.

showConfirmDialog

public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType,
                                    int messageType)
This method shows a confirmation dialog with the given message, title, messageType and optionType. The frame owner will be the same frame as the one that holds the given parentComponent. This method returns the option selected by the user.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
optionType - The optionType.
messageType - The messageType.
Returns:
The selected option.

showConfirmDialog

public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType,
                                    int messageType,
                                    Icon icon)
This method shows a confirmation dialog with the given message, title, optionType, messageType and icon. The frame owner will be the same as the one that holds the given parentComponent. This method returns the option selected by the user.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
optionType - The optionType.
messageType - The messsageType.
icon - The icon displayed.
Returns:
The selected option.

showInputDialog

public static String showInputDialog(Component parentComponent,
                                     Object message)
This method will show a QUESTION_MESSAGE input dialog with the given message. No selectionValues is set so the Look and Feel will usually give the user a TextField to fill out. The frame owner will be the same frame that holds the given parentComponent. This method will return the value entered by the user.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
Returns:
The value entered by the user.

showInputDialog

public static String showInputDialog(Component parentComponent,
                                     Object message,
                                     Object initialSelectionValue)
This method will show a QUESTION_MESSAGE type input dialog with the given message and initialSelectionValue. Since there is no selectionValues set, the Look and Feel will usually give a TextField to fill out. The frame owner will be the same as the one that holds the given parentComponent. This method will return the value entered by the user.
Parameters:
parentComponent - The component to find a frame in.
message - The message to display.
initialSelectionValue - The initially selected value.
Returns:
The value the user input.

showInputDialog

public static String showInputDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType)
This method displays a new input dialog with the given message, title and messageType. Since no selectionValues value is given, the Look and Feel will usually give the user a TextField to input data to. This method returns the value the user inputs.
Parameters:
parentComponent - The component to find a frame in.
message - The message to display.
title - The title of the dialog.
messageType - The messageType.
Returns:
The value the user input.

showInputDialog

public static Object showInputDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType,
                                     Icon icon,
                                     Object[] selectionValues,
                                     Object initialSelectionValue)
This method shows an input dialog with the given message, title, messageType, icon, selectionValues, and initialSelectionValue. This method returns the value that the user selects.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
messageType - The messageType.
icon - The icon displayed.
selectionValues - The list of values to select from.
initialSelectionValue - The initially selected value.
Returns:
The user selected value.

showInputDialog

public static String showInputDialog(Object message)
This method shows a QUESTION_MESSAGE type input dialog. Since no selectionValues is set, the Look and Feel will usually give the user a TextField to input data to. This method returns the value the user inputs.
Parameters:
message - The message to display.
Returns:
The user selected value.

showInputDialog

public static String showInputDialog(Object message,
                                     Object initialSelectionValue)
This method shows a QUESTION_MESSAGE type input dialog. Since no selectionValues is set, the Look and Feel will usually give the user a TextField to input data to. The input component will be initialized with the initialSelectionValue. This method returns the value the user inputs.
Parameters:
message - The message to display.
initialSelectionValue - The initialSelectionValue.
Returns:
The user selected value.

showInternalConfirmDialog

public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message)
This method shows an internal confirmation dialog with the given message. The internal frame dialog will be placed in the first JDesktopPane ancestor of the given parentComponent. This method will return the value selected.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message to display.
Returns:
The value selected.

showInternalConfirmDialog

public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType)
This method shows an internal confirmation dialog with the given message, optionType and title. The internal frame dialog will be placed in the first JDesktopPane ancestor of the given parentComponent. This method will return the selected value.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message to display.
title - The title to display.
optionType - The option type.
Returns:
The selected value.

showInternalConfirmDialog

public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType,
                                            int messageType)
This method shows an internal confirmation dialog with the given message, title, optionTypes and icon for the given message type. The internal confirmation dialog will be placed in the first instance of JDesktopPane ancestor of the given parentComponent.
Parameters:
parentComponent - The component to find a JDesktopPane in.
message - The message to display.
title - The title of the dialog.
optionType - The option type.
messageType - The message type.
Returns:
The selected value.

showInternalConfirmDialog

public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType,
                                            int messageType,
                                            Icon icon)
This method shows an internal confirmation dialog with the given message, title, option type, message type, and icon. The internal frame dialog will be placed in the first JDesktopPane ancestor that is found in the given parentComponent. This method returns the selected value.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message to display.
title - The title to display.
optionType - The option type.
messageType - The message type.
icon - The icon to display.
Returns:
The selected value.

showInternalInputDialog

public static String showInternalInputDialog(Component parentComponent,
                                             Object message)
This method shows an internal input dialog with the given message. The internal frame dialog will be placed in the first JDesktopPane ancestor of the given parent component. This method returns the value input by the user.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message to display.
Returns:
The user selected value.

showInternalInputDialog

public static String showInternalInputDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType)
This method shows an internal input dialog with the given message, title and message type. The internal input dialog will be placed in the first JDesktopPane ancestor found in the given parent component. This method will return the input value given by the user.
Parameters:
parentComponent - The component to find a JDesktopPane in.
message - The message to display.
title - The title to display.
messageType - The message type.
Returns:
The user input value.

showInternalInputDialog

public static Object showInternalInputDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType,
                                             Icon icon,
                                             Object[] selectionValues,
                                             Object initialSelectionValue)
This method shows an internal input dialog with the given message, title message type, icon, selection value list and initial selection value. The internal frame dialog will be placed in the first JDesktopPane ancestor found in the given parent component. This method returns the input value from the user.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message to display.
title - The title to display.
messageType - The message type.
icon - The icon to display.
selectionValues - The selection value list.
initialSelectionValue - The initial selection value.
Returns:
The user input value.

showInternalMessageDialog

public static void showInternalMessageDialog(Component parentComponent,
                                             Object message)
This method shows an internal message dialog with the given message. The internal frame dialog will be placed in the first JDesktopPane ancestor found in the given parent component.
Parameters:
parentComponent - The component to find a JDesktopPane in.
message - The message to display.

showInternalMessageDialog

public static void showInternalMessageDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType)
This method shows an internal message dialog with the given message, title and message type. The internal message dialog is placed in the first JDesktopPane ancestor found in the given parent component.
Parameters:
parentComponent - The parent component to find a JDesktopPane in.
message - The message to display.
title - The title to display.
messageType - The message type.

showInternalMessageDialog

public static void showInternalMessageDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType,
                                             Icon icon)
This method shows an internal message dialog with the given message, title, message type and icon. The internal message dialog is placed in the first JDesktopPane ancestor found in the given parent component.
Parameters:
parentComponent - The component to find a JDesktopPane in.
message - The message to display.
title - The title to display.
messageType - The message type.
icon - The icon to display.

showInternalOptionDialog

public static int showInternalOptionDialog(Component parentComponent,
                                           Object message,
                                           String title,
                                           int optionType,
                                           int messageType,
                                           Icon icon,
                                           Object[] options,
                                           Object initialValue)
This method displays an internal option dialog with the given message, title, option type, message type, icon, option list, and initial option value. The internal option dialog is placed in the first JDesktopPane ancestor found in the parent component. This method returns the option selected.
Parameters:
parentComponent - The parent to find a JDesktopPane in.
message - The message displayed.
title - The title displayed.
optionType - The option type.
messageType - The message type.
icon - The icon to display.
options - The array of options.
initialValue - The initial value selected.
Returns:
The option that was selected.

showMessageDialog

public static void showMessageDialog(Component parentComponent,
                                     Object message)
This method shows an INFORMATION_MESSAGE type message dialog.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.

showMessageDialog

public static void showMessageDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType)
This method shows a message dialog with the given message, title and messageType.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
messageType - The messageType.

showMessageDialog

public static void showMessageDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType,
                                     Icon icon)
This method shows a message dialog with the given message, title, messageType and icon.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
messageType - The messageType.
icon - The icon displayed.

showOptionDialog

public static int showOptionDialog(Component parentComponent,
                                   Object message,
                                   String title,
                                   int optionType,
                                   int messageType,
                                   Icon icon,
                                   Object[] options,
                                   Object initialValue)
This method shows an option dialog with the given message, title, optionType, messageType, icon, options and initialValue. This method returns the option that was selected.
Parameters:
parentComponent - The component to find a frame in.
message - The message displayed.
title - The title of the dialog.
optionType - The optionType.
messageType - The messageType.
icon - The icon displayed.
options - The options to choose from.
initialValue - The initial value.
Returns:
The selected option.

updateUI

public void updateUI()
This method resets the UI to the Look and Feel default.
Overrides:
updateUI in interface JComponent

JOptionPane.java Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.