Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

best way to update a JList

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, here's the method that adds the new list to the JPanel:


bp
 
Sheriff
Posts: 22573
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that worked perfectly,thanks!
bp
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic