15.2. JList
A JList presents a list of choices for selection. Either a single item or multiple items can be selected. In the following subsections, we present four approaches for creating a JList. The first approach creates a fixed set of choices by simply passing data directly to the JList. The second approach takes advantage of the default list model to support changeable choices. The third approach demonstrates a custom list model (data structure) for holding the list items. Finally, the fourth approach uses a custom renderer to build a custom JComponent for each item in the list.
JList with a Fixed Set of Choices
The simplest way to create a JList is to supply an array of strings to the JList constructor. Unlike an AWT List, a JList does ...
Get Core Web Programming, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.