• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

need help on JList

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic