| Java Sun >
Guidelines Home Page > Java Look and Feel Design Guidelines >
Part III: The Components of the Java Foundation Classes > 11: Text Components >
In a noneditable text field, users can select and copy text to paste elsewhere (something they cannot do with labels), but they cannot change the text in the fields. Only the application can change the contents of a noneditable text field. The background of a noneditable text field is the secondary 3 color defined in the application's color theme. In the default theme, the background color is gray, as shown in the following figure.Figure 175 Noneditable Text Field
When a text field has keyboard focus, it displays a blinking bar that indicates the insertion point. When users type in text that is too long to fit in the field, the text scrolls horizontally. By default, the background of an editable text field is white.Figure 176 Editable Text Field With Blinking Bar
The following figure shows a text field with the letters
Jeffer selected. The insertion point is at the end of the selected text and indicates that the text field has keyboard focus. The selected text is overwritten when the user types or pastes new text.
When keyboard focus enters a text field by some means other than a user's mouse click, select the entire contents of the text field. (This situation might occur if the user navigated into the text field with a mnemonic or with the Tab key, or if the initial focus when a dialog box opens is in the text field. ( Figure 84 shows an example of such a situation.) Users can then start typing characters to replace the existing text, or they can press the Tab key to move to the next field, leaving the original text intact. When the text is selected, pressing the left or right arrow keys deselects the text and moves the insertion point (if possible), enabling users to correct the text using only the keyboard. Of course, if users click in a text field, place the insertion point as close to the click point as possible, without selecting text.
To associate a mnemonic with a text field, you must give the text field a label. You can then assign a mnemonic to the label, and make the mnemonic give focus to the text field. For details, see Mnemonics in Labels. For keyboard operations appropriate to text fields, see Table 29.
Depending on the type of data, you might be able to check individual characters for errors as they are typed--for example, if users try to type a letter into a text field that should contain only numbers. In this case, do not display the character in the field. Instead, sound the system beep. If the user types three illegal characters in a row, display an Error alert box that explains the legal entries for the text field.
If you plan an action based on the string in the text field (such as searching for the string or performing a calculation), start the action when users signify that they have completed the entry by pressing Enter or by moving keyboard focus outside the text field. Do not start the action before the user has completed the text entry.
For keyboard operations for editable text fields, see Table 29.
|Java Look and Feel Design Guidelines, second edition.
Copyright 2001. Sun Microsystems, Inc. All Rights Reserved.