Java Reference
In-Depth Information
The
JOptionPane
component supports localized
JOptionPane
button labels. Out of the box,
the
JOptionPane
displays Chinese or Japanese button labels for the standard Yes, No, Cancel,
and OK buttons for the appropriate locale. For instance, the left side of Figure 9-14 shows buttons
with Japanese labels for Yes, No, and Cancel, and the right side of Figure 9-14 shows buttons with
Japanese labels for OK and Cancel. Obviously, you would need to change the message in the
option pane, but the buttons are set for you (assuming you have the fonts to support it).
Figure 9-14.
A JOptionPane with Japanese-language buttons
Thankfully, the 5.0 release of the JDK includes translations for the standard
JOptionPane
(as well as the
JFileChooser
and
JColorChooser
) labels. These are available for German (de),
Spanish (es), French (fr), Italian (it), Japanese (ja), Korean (ko), English, Swedish (sv), and
Chinese (Simplified/zh_CN and Traditional/zh_TW).
■
Tip
To start the Java runtime with a different language, just set the
user.language
property, as in
java -Duser.language=FR ClassName
. Then, whenever you create a
JOptionPane
, you would get the
French labels for Yes, No, OK, and Cancel. The button labels would be like those shown in Figure 9-14, but
without you needing to manually do the
UIManager.put()
calls. (Instead of
D'accord
, Sun chose to leave
OK as OK.)
ProgressMonitor Class
The
ProgressMonitor
class is used to report on the status of a time-consuming task. The class is
a special Swing class that's not a GUI component, an option pane, or a JavaBean component.
Instead, you tell the
ProgressMonitor
when each part of the task is done. If the task is taking an
extended length of time to complete, the
ProgressMonitor
displays a pop-up window like the
one shown in Figure 9-15.
Figure 9-15.
ProgressMonitor sample