Java Reference
In-Depth Information
Figure 9-3. Sample JOptionPane message pop-ups
Confirm Pop-Ups
The showConfirmDialog() and showInternalConfirmDialog() methods, by default, create a
pop-up with a QUESTION_MESSAGE type and the pop-up title “Select an Option.” Because confirm
dialog boxes ask a question, their default option type is YES_NO_CANCEL_OPTION , giving them Yes,
No, and Cancel buttons. The return value from a call to any of these methods is one of the
JOptionPane class constants YES_OPTION , NO_OPTION , or CANCEL_OPTION . No prizes for guessing
which constant maps to which option pane button! Figure 9-4 shows sample confirm pop-ups
created from the following lines of source:
JOptionPane.showConfirmDialog(parent, "Continue printing?");
JOptionPane.showInternalConfirmDialog(desktop, "Continue printing?");
Figure 9-4. Sample JOptionPane confirm pop-ups
Input Pop-Ups
By default, the showInputDialog() and showInternalInputDialog() methods create a
QUESTION_MESSAGE pop-up with an “Input” pop-up title. The option type for input dialogs is
OK_CANCEL_OPTION , giving them an OK and a Cancel button, and the option type isn't changeable.
The return data type for these methods is either a String or an Object . If you don't specify
selection values, the pop-up prompts the user with a text field and returns the input as a
String . If you do specify selection values, you get back an Object from the selection values
array. Figure 9-5 shows some input pop-ups created from the following lines of source:
JOptionPane.showInputDialog(parent, "Enter printer name:");
// Moons of Neptune
String smallList[] = {
"Naiad", "Thalassa", "Despina", "Galatea", "Larissa", "Proteus",
"Triton", "Nereid"} ;
 
Search WWH ::




Custom Search