| Java Sun >
Guidelines Home Page > Java Look and Feel Design Guidelines >
Part III: The Components of the Java Foundation Classes > 10: Basic Controls >
A list box is a one-column arrangement of items (text, graphics, or both) that enables users to set a variable or a property somewhere in the application. List boxes can be used as an alternative to combo boxes, radio buttons, and checkboxes. A similar control, also implemented with the
JList component, is the selectable list. For details, see Selectable Lists.
You can use a list box to present users with a set of exclusive or nonexclusive choices. For example, you might use a list box to present the days of the week, from which users could select one day on which to start their calendars, as shown in the following figure.Figure 159 Exclusive List Box
Figure 160 Nonexclusive List Box
When resizing a list component, be sure that it always displays a whole number of lines.
You can provide vertical and horizontal scrolling of the items in list components by placing the list inside a scroll pane. Users can then scroll the list as described in Scroll Panes.
If you place a list component in a scroll pane, set the vertical and horizontal scrollbars to appear only when needed. This behavior is the default behavior of scroll panes. If at all possible, display the list component with a width that makes horizontal scrolling unnecessary.
The JFC provides three selection models that you can use to enable users to select list items: single item, single range, and multiple ranges. Single-item selection provides users with an exclusive choice. Single-range and multiple-range selection provide users with nonexclusive choices.
When the user clicks an item in the list box, that item is chosen: the choice persists even when the user has moved on to the next component. When a user clicks an item in a selectable list, it is selected. If the user later selects another object, this selection disappears.
Despite the different selection models for the two kinds of list components, the methods for making those choices are the same. For simplicity, in the rest of this section, the word "selection" is used to encompass both behaviors.
For the keyboard operations appropriate for list boxes and selectable lists, see Table 19.Figure 161 Single-Item Selection in a List Component
You can enable users to select a single item or a range of items. Users select an item by clicking it. The item gets keyboard focus and becomes the anchor point of the selection. Users extend the selection by dragging or by moving the pointer to another item and Shift-clicking.
In Figure 162, the user first clicked Pineapple and then Shift-clicked Sausage.
Click here to view the corresponding code for Figure 162 (also available on the book's companion CD-ROM).
You can enable users to select a single item, a range of items, or multiple ranges of items (also known as "discontinuous," "discontiguous," or "disjoint" ranges). Users select a single item by clicking it and extend the selection by Shift-clicking. To start another range, users Control-click an item. That item then gets keyboard focus and becomes the anchor point of the new range. In addition, the selection of the item is toggled--if the item was initially selected, it is deselected, and vice versa. Shift-clicking extends the new range.
In the following figure, the user chose the first range by clicking Bell Pepper and then Shift-clicking Mushroom. The user chose additional ranges by Control-clicking Pepperoni and extending to Sausage with a Shift-click. Finally, the user deselected an item in the range by Control-clicking Pineapple.Figure 163 Multiple Ranges of Selected Items in a List Component
|Java Look and Feel Design Guidelines, second edition.
Copyright 2001. Sun Microsystems, Inc. All Rights Reserved.