File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList" Watch "JList" New topic
Author

JList

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
please can anyone tell me how i can add a single item/object to a JList?
thanks


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi Pete,
you can try this

Instead of a vector, you can also use any Object[].
Hope this helps
Rene
Shane Kirk
Greenhorn

Joined: Jul 19, 2002
Posts: 5
Rene's method works...but there's another way that might involve less overhead if you have a lot of insertions/deletions occuring in the JList data.
The JList's list model is a DefaultListModel. So, you could do something like the following.
DefaultListModel model = (DefaultListModel) myList.getModel();
model.addElement(myObject);
I can't remember off the top of my head if this fires an event for the JList to redraw itself or not. If not, a simple call to the JList's repaint method should probably suffice.
[ July 22, 2002: Message edited by: Shane Kirk ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList