Add Linked List to a JList  
Author Message
shaun





PostPosted: 2005-8-18 6:59:00 Top

java-programmer, Add Linked List to a JList Hi,

I have a linked list of Contact objects that hold names of contacts in
a class called ContactList. Is it possible to add this display this
linked list of contacts to a JList?

Thanks fo your help

 
shaun





PostPosted: 2005-8-18 7:07:00 Top

java-programmer >> Add Linked List to a JList Hi,

I have a class called ContactList that has a linked list of Contact
objects. Contact objects hold names of contacts. Is it possible to add
this linked list of contacts directly to a JList?

Thanks for your help


Shaun

 
Thomas Hawtin





PostPosted: 2005-8-18 7:24:00 Top

java-programmer >> Add Linked List to a JList shaun wrote:
>
> I have a class called ContactList that has a linked list of Contact
> objects. Contact objects hold names of contacts. Is it possible to add
> this linked list of contacts directly to a JList?

Pretty much.

List<Contact> contacts = new LinkedList<Contact>();
...
JList contactList = new JList();
...
contactList.setListData(contacts.toArray(new Object[0]));

(Note, that replaces the JList's current model, if you're interested in
that.)

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/