File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How can I make JList update when ListModel changed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can I make JList update when ListModel changed?" Watch "How can I make JList update when ListModel changed?" New topic
Author

How can I make JList update when ListModel changed?

Ren Shao
Ranch Hand

Joined: Dec 23, 2002
Posts: 51
hi, I have a JList and I use a DefaultListModel to store the list entries.
I have a button on that panel. When the button is clicked, I remove all the entries from DefaultListModel and add all entries back from a sql query result.(I have to do it that way)

My problem is, after I did the operation on my DefaultListModel above, the content of JList doesn't change(the database has been changed), however, sometimes it works.(some times not) I'm wondering that do I need to call a sort of refresh method on JList after I make changes on the ListModel.

If someone can help, that will be great.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Ren Shao
Ranch Hand

Joined: Dec 23, 2002
Posts: 51
hi, Craig, the code you show me is actually what I've done. It didn't work properly as the JList won't refresh every time I click the button.(Sometimes it does but most time it doesn't, do you know why?
[ September 22, 2004: Message edited by: Ren Shao ]
Ren Shao
Ranch Hand

Joined: Dec 23, 2002
Posts: 51
I know what's wrong, thanks!!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Ren Shao:
I know what's wrong, thanks!!


Care to share? This board is all about helping each other out. You could save someone hours of debugging just by explaining what your solution is.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I make JList update when ListModel changed?