Work with JList
The last component that we will examine is JList. This is Swing’s basic list class. It supports the selection of one or more items from a list. Although often the list consists of strings, it is possible to create a list of just about any object that can be displayed. JList is so widely used in Java that it is highly unlikely that you have not seen one before.
In the past, the items in a JList were represented as Object references. However, with the release of JDK 7, JList was made generic, and it is now declared like this:
class JList<E>
Here, E represents the type of the items in the list. As a result, JList is now type-safe.
NOTE
The discussion and example that follow use the generic version of JList. If your compiler predates ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access