JList : Java Glossary
home J words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
JList
The Swing equivalent of java.awt.List. A JList is a list of choices from which you can select one — like a Choice continuously displayed already opened up. Commonly you embed a JList in a JScrollPane in case the list is too large to display all at once. Then you can use JList. getSelectedIndex() and JList. ensureIndexIsVisible( index ) to ensure the index you want is scrolled into view. It looks like this:

JList screen shot

Unlike a JComboBox, you cannot add items one by one to the list of available JList choices. There is no addItem method. You must create a new Object[] or Vector and replace the entire list with setListData. You can of course use a DefaultListModel which does give you the individual add methods.

You will get two ListSelectionEvents, one when the mouse button goes down and one when it releases. This is not considered a bug.

Sun bug number 4323107 : JList generates two ListSelectionEvents per selection.

The removeAll method does not remove all the possible list selections. It is a vestigial method inherited from Container. Instead you must use DefaultListModel.clear.

Learning More

Sun’s Javadoc on the JList class : available:
Sun’s Javadoc on the JScrollPane class : available:
Sun’s Javadoc on the DefaultListModel class : available:

Sun’s Javadoc on the ListSelectionEvent class : available:

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] Visit DavidSuzuki.org
You are visitor number 14,039.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/jlist.html J:\mindprod\jgloss\jlist.html