wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes best way to update a JList 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 "best way to update a JList" Watch "best way to update a JList" New topic

best way to update a JList

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
I have an app I'm working on that reads an xml file, creates a map of objects, I then use the map to populate the list.

I have a search window that I want to use to narrow the list; when a user enters a character, I have a method that loops through the list, looks for that string, and only places matching objects in the new list.

So far it works in terms of what is viewable on the panel, but in the narrowed list I can't select anything....

What's the best way to accomplish this task?

I notice that I'm not removing the list that exists on the panel....maybe I need to do that. Any other ideas?
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Hi Edmund,

Please post an Short, Self Contained, Correct (Compilable), Example.
From this code I can't see anything. You create a new DefaultListModel and that's all. How do you change your list's model? The content of the listmodel shouldn't prevent you to select anything, so my guessing is that there's some problem in other part of your code.
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
sorry, here's the method that adds the new list to the JPanel:

Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

Try reusing the same JList but changing the model instead. So instead of you simply call That way, all the other stuff like listeners, fonts, borders etc will stay.

How To Ask Questions How To Answer Questions
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
that worked perfectly,thanks!
I agree. Here's the link: http://aspose.com/file-tools
subject: best way to update a JList
Similar Threads
JList not refreshing ?issue?
Question about Tree Node --Word Tree
JList Problem
Serializing/deserializing a list
Best way to keep track of record in JTable