• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I update the a JList?  RSS feed

 
Ron Sibayan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • 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".
 
Jason Steele
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!