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?
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.
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.