• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I update the a JList?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys,
I have a problem, does anyone know if theres a way I can update a JList rather than just adding to it? ie if the list is showing a range of variables in a vector,and one of these variables changes, I want the list to update so it only shows one instance of each object rather than what is happening now which is that the new value for the object is being added to the end of the list.
If anyone understood all that please help.
thanks
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would help to see your code. With a "JList", you can call the "setListData()" method with a Vector and it will construct a new List model for you behind the scenes. This replaces the model what was active. So every time the vector changes you need to re-build the List.
Alternately you can call the "getModel()" method, cast it as a "DefaultListModel" (if it is of that type) and add, remove or update elements as appropriate.
Finally you could create your own class that implements the "ListModel" interface and use it in your "JList".
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you could also just replace the ListModel with a new one. Both have the same affect. Not sure which would be the better performance getter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic