Java Reference
In-Depth Information
Table 9-3. JOptionPane Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
icon
Icon
Read-write bound
initialSelectionValue
Object
Read-write bound
initialValue
Object
Read-write bound
inputValue
Object
Read-write bound
maxCharactersPerLineCount
int
Read-only
message
Object
Read-write bound
messageType
int
Read-write bound
options
Object[]
Read-write bound
optionType
int
Read-write bound
selectionValues
Object[]
Read-write bound
UI
OptionPaneUI
Read-write bound
UIClassID
String
Read-only
value
Object
Read-write bound
wantsInput
boolean
Read-write bound
The wantsInput property is automatically set to true for the input dialog boxes or when the
selectionValues property is non- null . The inputValue property is the item picked from an
input dialog box. The value property indicates the option selected from the button area.
Displaying Multiline Messages
The maxCharactersPerLineCount property is set to an extremely large value, Integer.MAX_VALUE ,
by default. For some strange reason, the Swing developers chose not to provide a setter method
for this property. If you want to change the setting, you must subclass JOptionPane and override the
public int getMaxCharactersPerLineCount() method. This causes a long text message to be
broken up into multiple lines within an option pane. In addition, you cannot use any of the
factory methods because they don't know about your subclass.
To help you create narrow JOptionPane components, you can add the source shown in
Listing 9-2 to the OptionPaneUtils class definition shown earlier in Listing 9-1. The new method
provides a way of specifying the desired option pane character width.
 
Search WWH ::




Custom Search