Home > Software > Internationalization for Swing standard components

Internationalization for Swing standard components


Internationalization is a very hot topic, especially on desktop applications. Java offers very nice, easy-to-use and comprehensive tools for this. And, unlike Microsoft, there are not undocumented features. On what I’ll go a little bit deeper in here is not an “undocumented” feature, but a little bit harder to find documentation for. As said, localizing a Java desktop application (developed on Swing) is pretty easy and straightforward. But what is a little bit harder is to localize the Swing standard components, like a file chooser dialog or a confirmation dialog.

For changing the localized texts on this components is fairly easy: simply set a key on the UIManager.

UIManager.put(name, value);

You must do this before creating the component or call SwingUtilities.updateComponentTreeUI(rootComponent) after.

What is more difficult is to know the right names for each component. Below I described some of the most important keys, the associated Swing components and their meaning. I also attached a screenshot with a file chooser dialog to easily identify its components (on the description you will also find a number to refer to the component on the given screenshot). Please keep in mind that these are LnF dependent.

JFileChooser components

Key name Associated component Description Default value
FileChooser.openDialogTitleText JFileChooser The text on the title bar (open dialog) Open
FileChooser.saveDialogTitleText JFileChooser The text on the title bar (save dialog) Save
FileChooser.lookInLabelText JFileChooser The text for the label in front of the folder selection box (open dialog) – 1 Look In:
FileChooser.saveInLabelText JFileChooser The text for the label in front of the folder selection box (save dialog) – 1 Save In:
FileChooser.upFolderToolTipText JFileChooser The tooltip of the button for navigating to the parent folder – 2 Up One Level
FileChooser.homeFolderToolTipText JFileChooser The tooltip of the button for navigating to the home folder – 3 Desktop
FileChooser.newFolderToolTipText JFileChooser The tooltip of the button used to create a new folder – 4 Create New Folder
FileChooser.listViewButtonToolTipText JFileChooser The tooltip of the button for switching to list view – 5 List
FileChooser.detailsViewButtonToolTipText JFileChooser The tooltip of the button for switching to detailed view – 6 Details
FileChooser.fileNameHeaderText JFileChooser The text placed on the header column displaying the file name in the detailed view – 7 Name
FileChooser.fileSizeHeaderText JFileChooser The text placed on the header column displaying the file size in the detailed view – 8 Size
FileChooser.fileTypeHeaderText JFileChooser The text placed on the header column displaying the file type in the detailed view – 9 Type
FileChooser.fileDateHeaderText JFileChooser The text placed on the header column displaying the last modified date of the file in the detailed view – 10 Date Modified
FileChooser.fileAttrHeaderText JFileChooser The text placed on the header column displaying the file attributes in the detailed view Attributes
FileChooser.fileNameLabelText JFileChooser The text of the label in front of the textfield containing the selected file name – 11 File Name:
FileChooser.filesOfTypeLabelText JFileChooser The text for the label in front of the filter selection box – 12 Files of Type:
FileChooser.openButtonText JFileChooser The text on the button used to select the file on an open type dialog – 13 Open
FileChooser.openButtonToolTipText JFileChooser The tooltip text for the button used to select the file on an open type dialog – 13 Open selected file
FileChooser.saveButtonText JFileChooser The text on the button used to select the file on a save type dialog – 13 Save
FileChooser.saveButtonToolTipText JFileChooser The tooltip text for the button used to select the file on a save type dialog – 13 Save selected file
FileChooser.directoryOpenButtonText JFileChooser The text on the button used to open a folder while browsing – 13 Save
FileChooser.directoryOpenButtonToolTipText JFileChooser The tooltip text for the button used to open a folder while browsing – 13 Save selected file
FileChooser.cancelButtonText JFileChooser The text on the button used to cancel the file selection dialog – 14 Cancel
FileChooser.cancelButtonToolTipText JFileChooser The tooltip text for the button used to cancel the file selection dialog – 14 Abort file chooser dialog
FileChooser.updateButtonText JFileChooser
FileChooser.updateButtonToolTipText JFileChooser
FileChooser.helpButtonText JFileChooser
FileChooser.helpButtonToolTipText JFileChooser
FileChooser.newFolderErrorText JFileChooser The error text to appear when an error occurs while creating a new folder Error creating new folder
FileChooser.acceptAllFileFilterText JFileChooser The description, to appear in the filter combobox, for the filter used in the file chooser to accept all the files. All Files
OptionPane.yesButtonText JOptionPane The button caption for confirmation in an option dialog Yes
OptionPane.noButtonText JOptionPane The button caption for denying an option dialog No
OptionPane.cancelButtonText JOptionPane The button caption for aborting an option dialog Cancel
ProgressMonitor.progressText ProgressMonitor The text for the progress monitor Please wait

If you want to see all the keys defined in the UIManager that paste the code below that will output them.

UIDefaults defaults = UIManager.getDefaults(); 
System.out.println(defaults.size()+ " properties"); 
for (Enumeration e = defaults.keys(); 
    e.hasMoreElements();) { 
  Object key = e.nextElement(); 
  System.out.println(key + " = " + defaults.get(key)); 
}

This code doesn’t display the properties in the above table. Those properties are subject to localization and they could be displayed using UIManager.get(propertyName) or UIManager.getString(propertyName, locale).

Categories: Software Tags: , , ,
  1. March 6, 2008 at 7:09 am

    Thanx, this really helped me a lot.
    However I had to make a few changes to get bangla working in my pc.
    I had to make the changes mentioned here: http://shamsmi.blogspot.com/2008/03/internationalize-swings-jfilechooser-in.html

  2. December 20, 2008 at 9:34 am

    And what about detailed view of files at JFileChooser?
    In my java 1.5 I can localize them easily, but some things are arreared at java 1.6 – even standard java locales like It, Ko, tw_CN does not work😦

  3. Peter
    January 20, 2012 at 12:14 pm

    Hi Adrian, thanks for your artical but I use Java 1.6 and 1.7 and not all the keys name are accepted. For example these not accepted:
    FileChooser.openDialogTitleText
    FileChooser.saveDialogTitleText
    FileChooser.saveInLabelText
    FileChooser.fileNameHeaderText
    FileChooser.fileSizeHeaderText
    FileChooser.fileTypeHeaderText
    FileChooser.fileDateHeaderText
    FileChooser.fileAttrHeaderText
    FileChooser.directoryOpenButtonText
    FileChooser.directoryOpenButtonToolTipText
    FileChooser.newFolderErrorText
    FileChooser.acceptAllFileFilterText
    OptionPane.yesButtonText
    OptionPane.noButtonText
    OptionPane.cancelButtonText
    ProgressMonitor.progressText

    I don’t understand it because GUI elemts of the JFileChooser are existing for those not accepted keys.

    Please You advise me where I find those keys in Java documentation or any other internet resource. Those not accepted keys I don’t find in Java documentation too. Where You find it?

    Thanks.

  1. February 6, 2015 at 1:15 am
  2. February 25, 2015 at 6:54 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: