Externalizing text strings with the visual editor

If you are writing an application that will be deployed for use in different languages, any text that is visible to the user needs to be translated.

Rather than translating the string in the Java source file and having to create a new executable for each language, Java lets you use resource bundles to redirect the string through a properties file. For more information about externalizing strings, see Externalizing strings.

The visual editor for Java supports displaying the externalized strings. They will show up normally with the actual values stored in the resource file. However, changing the text properties after externalizing will overwrite the externalization, not change the resource file. To reflect changes to the resource file, the visual editor must be closed and reopened. Be careful when you choose strings to externalize. By default, all strings are externalized, even strings which are not displayed on the GUI. For example, font names.

Before externalizing the string, the string will be presented in the source as a literal. For example:

ivjJFrame.setTitle("Hello World");

After using the Externalize Strings wizard, the string will be retrieved from a static lookup in a file that retrieves the value from a resource bundle.

ivjJFrame.setTitle(Messages.getString("Hello_World_1"));
//$NON-NLS-1$

The string that is the argument to the setTitle method call is externalized, but the string that represents the bundle key is not because it is not a user visible string. To indicate that this string is not a user visible string so the Externalize Strings wizard does not attempt to retrieve this from a bundle, the comment //$NON-NLS-1$ is appended to the statement with the 1, indicating that it is referring to the first string occurrence on the line.

 

Parent topic

Developing Java classes with the visual editor