Java Reference
In-Depth Information
Table 9-5. JOptionPane UIResource Elements (Continued)
Property String
Object Type
OptionPane.warningDialog.titlePane.foreground
Color
OptionPane.warningDialog.titlePane.shadow
Color
OptionPane.warningIcon
Icon
OptionPane.warningSound
String
OptionPane.windowBindings
Object[ ]
OptionPane.yesButtonMnemonic
String
OptionPane.yesButtonText
String
OptionPane.yesIcon
Icon
OptionPaneUI
String
One good use of the resources in Table 9-5 is for customizing default button labels to
match the locale or language of the user. For instance, to change the four labels for the Cancel,
No, OK, and Yes buttons into French, add the following code to your program. (You may be
able to get the translated text from a java.util.ResourceBundle .)
// Set JOptionPane button labels to French
UIManager.put("OptionPane.cancelButtonText", "Annuler");
UIManager.put("OptionPane.noButtonText", "Non");
UIManager.put("OptionPane.okButtonText", "D'accord");
UIManager.put("OptionPane.yesButtonText", "Oui");
Now when you display the option pane, the buttons will have localized button labels. Of
course, this would require translating the messages for the option pane, too. Figure 9-13 shows
how a pop-up would look for the following line of source that asks if the user is 18 or older.
Because the pop-up window title isn't a property, you must pass the title to every created
dialog box.
int result = JOptionPane.showConfirmDialog(
aFrame, "Est-ce que vous avez 18 ans ou plus?", "Choisisez une option",
JOptionPane.YES_NO_CANCEL_OPTION);
Figure 9-13. A JOptionPane in French
 
Search WWH ::




Custom Search