A JList renders like this:
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.
Unlike JComboBox, JList does not notify the DataModel of selection changes.
You will get two ListSelectionEvents, one when the mouse button goes down and one when it releases. This is not considered a bug.
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.
What if the field you want to display is not the field the toString method displays from your data objects? You will need to create your own ListCellRender classe to select the field you want to display.
This page is posted
Optional Replicator mirror
Please read the feedback from other visitors, or send your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Your face IP:[18.104.22.168]
You are visitor number|