JavaFX Scene Builder: User Guide

10 Internationalizing Your FXML Layout

This chapter discusses the internationalization support that is provided with JavaFX Scene Builder.

The JavaFX Scene Builder tool enables you to adapt your FXML layout to various languages and regions through the use of resource bundle files. When you add a new element to the Content panel, the element's visible property values are set to default values. For example, a button element has a default Text property value of Button. This default value can be changed with an internationalized string by hovering the cursor over the right of the Text property text field, clicking the round cog icon that appears, and then selecting Replace with Internationalized String, as shown in Figure 10-1. Notice that the default value is then replaced by %key.unspecified, which you need to replace with the appropriate resource key name that is defined in your resource file. The percent sign (%) prefix is a visible indicator that the Text property value following it is a resource key name. You can still use the percent sign as a first character for the Text property value. If you have not selected the Replace with Internationalized String setting, then in the FXML file, the percent sign will appear as \%. This indicates that the rest of the property value has no link with internationalization and that it is not a key name.

Figure 10-1 Internationalizing a Button Element

Description of Figure 10-1 follows
Description of "Figure 10-1 Internationalizing a Button Element"

The HelloI18N sample can help show the internationalization support. The sample is included with the JavaFX Scene Builder samples bundle. Its Main class shows how to load the resource bundle. The sample includes the and files. When you open the <javafx-scenebuilder-samples-2_0-install-dir>/HelloI18N/src/helloi18n/HelloI18N.fxml file, the FXML file is opened in its own window and you see a button that is labeled %button.text. To localize this label, select Preview from the Menu bar, select Internationalization, Set Resource, and then open the <javafx-scenebuilder-samples-2_0-install-dir>/HelloI18N/src/helloi18n file.

Figure 10-2 shows that the button element's Text property value was set to use the button.text resource key, which is defined in the file as having the value of HelloI18N. The percent sign in front of the Text property's text field is a visible indicator that the value in the text field is a resource name. If you replace the value assigned to button.text in the file and save the change, the new value is immediately reflected in the button displayed on the Content panel. You can define additional resource keys in your resource bundle files and use them in the FXML layout you are building.

Select the Preview from the Main menu, then Internationalization command, and then Set Resource. In the select Internationalization Resource File dialog box, select the file to see how the HelloI18N sample application appears when using the French resource file. Notice that the text displayed on the button is now Bonjour. Changes you make and save to the resource file are reflected in the FXML layout you are working on in the JavaFX Scene Builder tool.

Figure 10-2 Using Resource Key Value to Internationalize the Text Property Value

Description of Figure 10-2 follows
Description of "Figure 10-2 Using Resource Key Value to Internationalize the Text Property Value"

Close Window

Table of Contents

JavaFX Scene Builder: User Guide

Expand | Collapse