Java Sun >
Guidelines Home Page >  Java Look and Feel Design Guidelines
>
Part III: The Components of the Java Foundation Classes
> 11: Text Components >
Text Fields
  Previous Next Contents/Index/Search


Text Fields

A text field is a rectangular area that displays a single line of text. A text field can be editable or noneditable.

Noneditable Text Fields

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

 

Noneditable Text Field

Editable Text Fields

In an editable text field, users can type or edit a single line of text. For example, a find dialog box has a text field in which users type a string for which they want to search.

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.

The following figure shows an editable text field with keyboard focus. The Language label is a separate component from the text field.

Figure 176   Editable Text Field With Blinking Bar

 

Blinking Bar in Text Field

In an editable text field, users can:

  • Insert characters at the insertion point and replace selected text by typing
  • Cut, copy, and paste text by using menu commands or keyboard shortcuts (Ctrl-X for Cut, Ctrl-C for Copy, and Ctrl-V for Paste)
  • Set the insertion point by single-clicking
  • Select a word by double-clicking
  • Select the entire line of text by triple-clicking
  • Select a range of characters by dragging
  • Select everything by navigating to the text field using the Tab key or the label's mnemonic

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.

Figure 177   Editable Text Field With Selected Text

 

Selected Text in Text Field

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.
Previous Next Contents/Index/Search
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
JavaOne Banner Java 8 banner (182)