Java Reference
In-Depth Information
Table 13-9. JList UIResource Elements (Continued)
Property String
Object Type
List.lockToPositionOnScroll
Boolean
List.rendererUseListColors
Boolean
List.rendererUseUIBorder
Boolean
List.selectionBackground
Color
List.selectionForeground
Color
List.timeFactor
Long
ListUI
String
As with most of the UIResource properties, the names of most of the properties are self-
explanatory. One property, List.timeFactor , requires a bit of extra descriptive text. By default,
the JList comes with behavior for keyboard selection. As you type, the JList will find the
entry that matches what you've typed so far. This is done with the help of the public int
getNextMatch(String prefix, int startIndex, Position.Bias bias) method. The “so far” bit
is controlled by the List.timeFactor setting. As long as the delay between keystrokes doesn't
exceed the number of milliseconds specified by List.timeFactor (default of 1000), the new key
pressed is added to the prior keys. Once the factor is exceeded, the search string is reset.
Creating a Dual List Box
The example presented in this section creates a new Swing component called a DualListBox . The
primary purpose of a dual list box is to create two lists of choices: one to pick from and one that
makes up your result set. This works great when the initial choice list is sizable. Trying to multi-
select from a JList that contains many selections across multiple screens can be annoying,
especially if you happen to deselect what you've already selected because you didn't have the
Shift or Ctrl key held down. With a dual list box, the user selects items in the first list and moves
them into the second. The user can easily scroll through the two lists without fear of accidentally
deselecting anything. Figure 13-12 shows how the DualListBox might look in use.
Figure 13-12. The DualListBox in action
 
Search WWH ::




Custom Search