Java Reference
In-Depth Information
Option Pop-Ups
The showOptionDialog() and showInternalOptionDialog() methods provide the most flexibility
because they allow you to configure all the arguments. There are no default arguments, and the
return value is an int . If an options argument is not specified, the return value will be one of the
constants listed in Table 9-1. Otherwise, the value returned represents the component position
of the selected option from the options argument. Figure 9-6 shows a couple of input pop-ups
created from the following lines of source, in which icons (instead of text) are provided on the
buttons:
Icon greenIcon = new DiamondIcon(Color.GREEN);
Icon redIcon = new DiamondIcon(Color.RED);
Object iconArray[] = { greenIcon, redIcon} ;
JOptionPane.showOptionDialog(source, "Continue printing?", "Select an Option",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, iconArray,
iconArray[1]);
Icon blueIcon = new DiamondIcon(Color.BLUE);
Object stringArray[] = { "Do It", "No Way"} ;
JOptionPane.showInternalOptionDialog(desktop, "Continue printing?",
"Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
blueIcon, stringArray, stringArray[0]);
Figure 9-6. Sample JOptionPane option pop-ups
Caution When using a factory method to show a JOptionPane within a JDialog , the dialog box is
automatically modal, preventing another window from getting the input focus. When showing the JOptionPane
within a JInternalFrame , the internal frame might be modal, but other windows might not be. Therefore,
a user could do something within one of the other windows of the application, including an action on the
JDesktopPane .
JOptionPane Properties
Table 9-3 shows the 15 properties of JOptionPane . These properties are accessible only if you
don't use one of the factory methods of JOptionPane . For most of the arguments, their meaning
maps directly to one of the constructor arguments.
 
Search WWH ::




Custom Search