aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "best way to update a JList" Watch "best way to update a JList" New topic
Author

best way to update a JList

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
Hi,
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?
bp
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: 85
sorry, here's the method that adds the new list to the JPanel:


bp
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
that worked perfectly,thanks!
bp
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best way to update a JList