| java.sun.com > Guidelines Home Page > Java Look and Feel Design Guidelines > Part III: The Components of the Java Foundation Classes > 11: Text Components |
Text components enable users to view and edit text in an application. The simplest text component you can provide is a label, which presents read-only information. A label is usually associated with another component and describes its function. A text field is a rectangular area that displays a single line of text, which can be editable or noneditable. A password field is an editable text field that displays masking characters in place of the characters that the user types.
Other text components display multiple lines of text. A text area displays text in a single font, size, and style. You can configure an editor pane to display different types of text through the use of a plug-in editor. The JFC editors include a plain text editor, a styled text editor, an RTF (rich text format) editor, and an HTML (Hypertext Markup Language) editor.
Figure 169 Text Components
Make your
text easier to localize by using resource
bundles. A resource
bundle stores text separately so that localizers don't have to change the
application's source code to accommodate translation.
For guidelines on translating text, see Planning for Internationalization and Localization.
A label consists of read-only text, graphics, or both. Labels serve two functions in an application:
Users cannot select a label or any of its parts.
You can associate a label with a component (such as a text field, slider, or checkbox) to describe the use of the component.
In Figure 170, the Salary Contribution label lets users know they can use the slider to adjust their salary contribution.
Click here to view the corresponding code for Figure 170 (also available on the book's companion CD-ROM).
You can also use a label to describe a group of components.
In Figure 171, the Color label describes a group of three radio buttons. The other text (Red, Yellow, and Blue) is part of the radio buttons and not a separate component. The Color label is not a separate component for the purpose of navigation.
Click here to view the corresponding code for Figure 171 (also available on the book's companion CD-ROM).
Keep label
text brief, and use terminology that is
familiar to users.
Use headline
capitalization in the label text and
place a colon at the end of
the text.
You can make a label available or unavailable so that its state is the same as that of the component it describes. Available labels are drawn in the primary 1 color defined in the application's color theme. Unavailable labels are drawn in the secondary 2 color defined in the application's color theme. The following figure shows an available and unavailable label.
Figure 172 Available and Unavailable Labels
Make a label
unavailable when the component it
describes is unavailable.
You can specify a mnemonic for a label. When the mnemonic is activated, it gives focus to the component that the label describes. This technique is often used with a label that accompanies an editable text field. In the following figure, the text field gets focus when users press Alt-N.
Figure 173 Label With a Mnemonic
If you can't
add a mnemonic directly to the component
that requires one, as
in the case of an editable text field, place the mnemonic in the component's
label.
The
displayedMnemonic property can be
used to specify the mnemonic in
a label.
The
labelFor property can be used to
associate a label with another
component so that the component gains focus when the label's mnemonic is
activated. This practice automatically sets the target's accessible name. The
labelFor property is most easily set by using the
JLabel.setLabelFor() method.
For a description of the alignment of labels and the spacing between a label and its components, see Label Alignment and Spacing.
You can use a label to communicate status or give information to users. In addition, you can instruct your application to alter a label to show a change in state.
The progress bar in Figure 174 uses two labels that change as the operation progresses. The application changes the top label to reflect the file currently being copied, and it updates the bottom label as the progress bar fills.
Click here to view the corresponding code for Figure 174 (also available on the book's companion CD-ROM).
Use sentence
capitalization in the text of a label
that communicates status.
Do not provide end punctuation unless the text is a complete sentence.
To ensure
that the information in a status label is
accessible to all users, the
accessibleDescription property of the window containing the label
should be set to the text of the label. Whenever the label changes, a
VISIBLE_PROPERTY_CHANGE event should be generated to cue assistive
technology to read the label again.
| Java Look and Feel Design Guidelines, second edition.
Copyright 2001. Sun Microsystems, Inc. All Rights Reserved. |