O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

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

The JList Class

The JList class is the generic Swing implementation of a list component. The class works reasonably well as a drop-in replacement for the AWT List class. If the selection mode is set appropriately, you can make multiple selections by clicking with the mouse while holding down the “Shift” or “Ctrl” modifier keys. Unlike AWT, the JList class does not provide scrolling capabilities; it must be set as the viewport of a JScrollPane in order to support scrolling. Figure 7.8 shows the JList component with three separate look-and-feels.

The JList component in the three look-and-feels

Figure 7-8. The JList component in the three look-and-feels

Properties

The JList class essentially combines the features of the data model, the selection model, and the cell renderer into a single Swing component. The properties of the JList class are shown in Table 7.9.

Table 7-9. JList Properties

Property

Data Type

get

is

set

bound

Default

See also properties from JComponent (Table 3.5)       

model

ListModel

•

 

•

•

selectionModel

ListSelectionModel

•

 

•

•

DefaultListSelectionModel()

UI

ListUI

•

 

•

•

from L&F

UIClassID*

String

•

   

"ListUI"

accessibleContext*

AccessibleContext

•

   

JList.AccessibleJList()

anchorSelectionIndex

int

•

   

cellRenderer

ListCellRenderer

•

 

•

•

from L&F

firstVisibleIndex ...

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