*
The moose likes Swing / AWT / SWT and the fly likes Update JList inside JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Update JList inside JPanel" Watch "Update JList inside JPanel" New topic
Author

Update JList inside JPanel

Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
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

Joined: May 17, 2003
Posts: 84
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: Update JList inside JPanel
 
Similar Threads
How to add JScrollPane in a JList ?
JFileChooser showing twice
Restrict drops to JPanel where it's drags are from.
JList deleting multiple items
Populating JList in Parent window from Child window's save button