JList component shows a number of items inside a single box. Figure 6.1 shows an admittedly silly example. The user can select the attributes for the fox, such as “quick,” “brown,” “hungry,” “wild,” and, because we ran out of attributes, “static,” “private,” and “final.” You can thus have the private static final fox jump over the lazy dog.
As of Java SE 7,
JList is a generic type. The
type parameter is the type of the values the user can select. In this example, we use a
To construct this list component, start out with an array of strings and pass that array to the
JList constructor: ...