Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes need help on JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help on JList" Watch "need help on JList" New topic
Author

need help on JList

catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
i have a problem in JList... Normally i just set the number items to be dispalyed in the Jlist in arrays,
String methods[] = {"setData", "getId", "getName", "getSalary", "getAge", "toString"};
JList listmeth= new JList(methods);

what if i am not intializing the methods and just applying a call method to do that..
When i click a button i would be able to tokenize words from a file...
i would need to take certain words from the tokenized words and add it into a Jlist... Please help me...I have until the part of tokenizing the words and adding the words i needed to display inside an array.. but do no how to add it into a Jlist..
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a DefaultListModel, and it's addElement() method

DefaultListModel listModel = new DefaultListModel();
JList list = new JList(listModel);
for(iterate the array)
{
listModel.addElement(...)
}

then later you just add whatever you want to the listModel
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need help on JList
 
Similar Threads
How can I make JList update when ListModel changed?
JList Refresh
Using Drag and drop with JLists to fire an event
regarding jFileChooser
updating custom JList