• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best way to update a JList

 
Edmund Castermund
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, here's the method that adds the new list to the JPanel:


bp
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edmund Castermund
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that worked perfectly,thanks!
bp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic