Ever since it was created the javax.swing.DefaultListModel class
documentation has read as follows:
"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."
This text clearly indicates that the authors understand that the
implementation is inadequate, but contains no committment to do anything
about the inadequacies. I have checked and even in JDK 1.5 the
implementation remains unchanged.
In particular there is no way to populate an instance of DefaultListModel
except by a loop. For example:
DefaultListModel dlm = new DefaultListModel();
dlm.ensureCapacity(aVector.size());
Iterator iter = aVector.iterator();
while(iter.hasNext())
{
dlm.addElement(iter.next());
}
selectedList = new JList(dlm);
If DefaultListModel implemented the Collection interface then I could simply
say:
DefaultListModel dlm = new DefaultListModel();
dlm.addAll(aVector);
selectedList = new JList(dlm);
Or if convenience constructors were added:
DefaultListModel dlm = new DefaultListModel(aVector);
selectedList = new JList(dlm);
Is there some alternative that I am missing? Is there some technical reason
or policy why this known deficiency has not been resolved?

Signature
Jim Cobban jcobban@magma.ca
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438
Thomas Weidenfeller - 03 Nov 2004 09:09 GMT
> This text clearly indicates that the authors understand that the
> implementation is inadequate, but contains no committment to do anything
> about the inadequacies. I have checked and even in JDK 1.5 the
> implementation remains unchanged.
Yes, Swing is full of wishful thinking.
> Is there some alternative that I am missing?
Implement your own ListModel.
/Thomas