Java Sun >
Guidelines Home Page >  Java Look and Feel Design Guidelines
>
Part III: The Components of the Java Foundation Classes
> 10: Basic Controls >
List Boxes
  Previous Next Contents/Index/Search


List Boxes

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

 

Exclusive List Box

Or, you might use a list box to display pizza toppings, from which users could make several choices, as shown in the following figure.

Figure 160   Nonexclusive List Box

 

Nonexclusive List Box

 


Note — Throughout this section, list boxes and selectable lists are referred to as list components when their behavior and appearance is the same.


  Use headline capitalization in list components.

  Provide a label with a mnemonic to enable keyboard navigation into list components.

  When resizing a list component, be sure that it always displays a whole number of lines.

Scrolling

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.

Selection Models for List Components

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.

Single Item

You can enable users to select a single item by clicking it. The item gets keyboard focus. The prior selection, if any, is deselected. In the following figure, the user has selected Thursday.

Figure 161   Single-Item Selection in a List Component

 

Single-Item Selection

Single Range of Items

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).

Figure 162   Range of Selected Items in a List Component

 

Range of Selected Items

Multiple Ranges of Items

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

 

Multiple Ranges of Selected Items


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)