Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updateable JList

 
Will Dietrich
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This question is for the second part of a much larger project I am working on for my first CompSci class. We are creating an address book with search, sort, add functionality etc. The functionality has already been implemented and works well in a command line interface however the second half of the assignment is to translate the command line into a GUI. I currently have a clickably JList that brings up the information of a contact when the contact is clicked in a JList. In order to implement the search functionality I would like to update my JList with all of the valid contacts that match my search criteria. The way my program currently works is that I have all of my contacts in an array which I add to my JList. When the user has indicated that they would like to search for a name two popup windows are created which accept the users first and last name then feed this data to my search method. My search method returns an array of contacts which I would like to load exclusively into my JList for the user to click and examine the contacts.

What I am unsure of right now is how it would be best to "refresh" my JList with only the results that are in my array of contacts that are returned by my search. Does anyone have any advice?
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will,
Welcome to the Ranch.

In pseudo code:
1) Gather user input
2) Pick out items from your main list which match your search criteria
3) Dump the picked items in an appropriate collection
4) Invoke JList#setListData and pass this new collection.

 
Will Dietrich
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow that's so awesome thanks!

Man I was reading all over the API and I totally skipped over the setListData method. Thank you so much, that was perfect!
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
Swing components strongly follow MVC. Almost always there will be a method which will allow you to tweak the underlying model.
Also, in case you haven't noticed, the API carries links to "How to user xxxcomponent.." which contains examples which are really useful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic