Java Reference
In-Depth Information
The pretty little icon comes for free.
How It Works
All the work is done by the static showMessageDialog() method in the JOptionPane class. What you
get is controlled by the arguments that you supply, and the Swing look-and-feel that is in effect. By de-
fault this corresponds to the cross-platform look-and-feel, and this is what Figure 20-4 shows. You get
the icon that you see in the dialog because you specified the message type as INFORMATION_MESSAGE .
You can try plugging in the other message types to see what you get.
Instant Input Dialogs
JOptionPane has four static methods that you can use to create standard modal dialogs for user input:
showInputDialog(Object message)
This method displays a default modal input dialog with a text field for input. The message you pass as
the argument is set as the caption for the input field, and the default also supplies an OK button, a Cancel
button, and Input as a title. For example, if you pass the message "Enter Input:" as the argument, as in
the following statement:
String input = JOptionPane.showInputDialog("Enter Input:");
the dialog shown in Figure 20-5 is displayed.
FIGURE 20-5
 
 
Search WWH ::




Custom Search