aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Updateable JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updateable JList" Watch "Updateable JList" New topic
Author

Updateable JList

Will Dietrich
Greenhorn

Joined: Dec 09, 2009
Posts: 5
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

Joined: Jul 26, 2007
Posts: 9995
    
    7

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Will Dietrich
Greenhorn

Joined: Dec 09, 2009
Posts: 5
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

Joined: Jul 26, 2007
Posts: 9995
    
    7

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Updateable JList
 
Similar Threads
Project Help
Serching for a surname in my collection
Set up Jlist
Project Help
Cell Widget Table in GWT 2.1.0 with expanded/collapsed rows