6.1.2. List Models

In the preceding section, you saw the most common method for using a list component:

1. Specify a fixed set of strings for display in the list.

2. Place the list inside a scroll pane.

3. Trap the list selection events.

In the remainder of the section on lists, we cover more complex situations that require a bit more finesse:

• Very long lists

• Lists with changing contents

• Lists that don’t contain strings

In the first example, we constructed a JList component that held a fixed collection of strings. However, the collection of choices in a list box is not always fixed. How do we add or remove items in the list box? Somewhat surprisingly, there are no methods in the JList class to achieve this. Instead, you have to understand ...

Get Core Java® Volume II—Advanced Features, Ninth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.