Cover Page by Gary Cornell, Cay S. Horstmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

6.1.1. The JList Component

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

Image

Figure 6.1. A list box

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 JList<String>.

To construct this list component, start out with an array of strings and pass that array to the JList constructor: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required