• Post Reply Bookmark Topic Watch Topic
  • New Topic

Remove JList

 
Eric Gero
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have been messing around with a small application as a learning experience. I have a JList in a JScrollPane, and this works fine. I added a ListSelectionListener with the idea that when an item was selected in the JList, the JList would be removed from the JScrollPane, new items a new JList created, and the new JList put back into the JScrollPane. Surprise surprise, this doesn't seem to work. What is the best way to go about something like this? Should I try to remove components when updating, or update the ones that are already there?

Thanks,
Eric
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the best way to do this is to create a new model, and set it as the list's model.
no need to remove/add the JList

here's a simple demo
 
Eric Gero
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense now. Thanks for your help!

Eric
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!