Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

DefaultListModel should implement Collection Interface

Thread view: 
Jim Cobban - 02 Nov 2004 21:20 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.