Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help on JList

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic