Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList

 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please can anyone tell me how i can add a single item/object to a JList?
thanks
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pete,
you can try this

Instead of a vector, you can also use any Object[].
Hope this helps
Rene
 
Shane Kirk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic