Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

JList essence.

JComboBox essence.

For manipulating a JList's contents we can use this.

Associate.

Fill it.

JList can't scroll.

Allow one line selection only.

Event handling.

When a JList line is selected, this method is called ...

and the line number chosen is determined.

First line is zero.

JComboBox ...

registers this event listener,

so this method will be called.

Selected line number.

===========

NOTES

===========

It's common practice to postpone getting the selected index, until a button is clicked, for example. In that case the class doesn't have to be an Item listener or a ListSelectionListener !

===

JList's getSelectedIndex returns -1 if the user hasn't selected a line yet. (Doesn't apply to this example)

.