• 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

Update JList inside JPanel

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JList inside a Jpanel, and I want to update it. My code is:

This creates a List in my JPanel, and now I want to update the content of my List, I'm trying to find something similar to Contenido.Lista = new Lista(DefaultListModel) or something like this, but obviuosly this is not working, I don't know how to get my List form my Panel so I can change it's content, anyone can help me? Thanks.
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, as usual, doing some testing before posting is useful, simply by doing Lista.setModel(DefaultListModel) it works. So if anyone has a better way of doing it, please post it, if not, I'll keep this one, Thanks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could create a DefaultListModel, create the JList with that and keep a reference to that DefaultListModel.
Then, when you need to change the contents, you can call clear() and then addElement() for all elements you want to show.

Only difference is in the number of objects you create, the difference is not that big.
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic