I don't have a List (java.util.List) . . . just a listModel (javax.swing.DefaultListModel) and a JList. I initialize it like this:
I looked up ListModel on the java.sun.com page and got the following description:
public interface ListModel
This interface defines the methods components like JList use to get the value of each cell in a list and the length of the list. Logically the model is a vector, indices vary from 0 to ListDataModel.getSize() - 1. Any change to the contents or length of the data model must be reported to all of the ListDataListeners.
Actually, I'm using DefaultListModel, which extends AbstractListModel, which implements ListModel. I'm not sure how I arrived at DefaultListModel (probably through some example code
).
Here's the java.sun.com description of DefaultListModel:
public class DefaultListModel
extends AbstractListModel
This class loosely implements the java.util.Vector API, in that it implements the 1.1.x version of java.util.Vector, has no collection class support, and notifies the ListDataListeners when changes occur. Presently it delegates to a Vector, in a future release it will be a real Collection implementation.
So, since DefaultListModel is Vector-like, it makes sense to me to save it instead of the JList GUI component. Thoughts?
Thanks for discussing this-- I really want to understand it better.
[ April 08, 2008: Message edited by: Jess Dancel ]