当前页面: 开发资料首页 → Netbeans 专题 → 在 NetBeans IDE 中对 GUI 窗体进行国际化(1)
摘要: The following tutorial shows you ways how to internationalize GUI forms in NetBeansTM IDE 5.0. In the first exercise, we will use the GUI Builder's string editor to set the display text for a GUI component with an internationalized string as you design the form. The second exercise shows you how to use the Internationalization wizard to internationalize hard-coded strings in multiple files at once. The last exercise shows you how to internationalize strings in a single file and how to easily insert an internationalized string in source code while you are coding.
Expected duration: 30 minutes
This tutorial assumes you have some basic knowledge of, or programming experience with, the following technologies:
Before you begin, you need to install the following software on your computer:
Internationalization permits applications to be adapted to various languages and regions without requiring engineering changes or recompilation. Internationalized programs enable textual elements, such as status messages and GUI component labels, to be stored outside the source code and retrieved dynamically rather than hard-coded in the program.
You typically store your internationalized strings in properties files, in the form of key/value pairs. The key is the identifier used by the program to retrieve the text, and the value is the actual text. You create one properties file for each locale (or language) in which you translate the program. The keys are the same in each locale - only the strings are different.
The IDE provides tools for doing each of the following:
In this exercise we will open the demo Java application project, which contains a well-known find dialog created using GUI Builder (Matisse). Next, we will create a new properties file which will contain internationalized strings. Then, we will use GUI Builder's string editor to change a text of components to an internationalized strings. In order to test our internationalized GUI form, we will add a new locale to properties file and run the form in the non-default locale.
To view a demonstration of how to create this GUI form, click View Demo.
|
We will now use the GUI builder to enter internationalized strings for the JLabels and JButtons in the form.
Repeat the previous steps for all components so that the form looks like the following picture:
To view a demonstration of internationalizing jLabel1 , click View Demo
The new locale appears below the Bundle Properties node, as shown below:
The IDE runs the FindDialog dialog in the Spanish locale.