List and JList

List components represent choices. They can be in single-selection mode (one item) or multi-selection mode (more than one item). Let's create an example list in the interactive interpreter.

>>> from javax.swing import JList
>>> list_items = ["Bruce", "Darrell", "Tony", "Debbie", "Karen"]
>>> list = JList(list_items)

Here's the interactive session to create a frame:

>>> from javax.swing import JFrame
>>> frame = JFrame("JList example")
>>> frame.contentPane.add(list)
>>> frame.pack()
>>> frame.visible=1

List Events

Now we want to do something with our list—that is, handle the list events—so we need to inspect JList's event properties (or look them up in the Java API documentation).

Here's the interactive session to inspect the ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with O’Reilly online learning.

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