O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

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

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 ...

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