File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Please Help: JList selectable options from 'name' field from each object in a HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Please Help: JList selectable options from Watch "Please Help: JList selectable options from New topic
Author

Please Help: JList selectable options from 'name' field from each object in a HashMap

Jasper Vader
Ranch Hand

Joined: Jun 10, 2002
Posts: 57
hi there.
i have three classes...
HolderFrame
Company
Employee
... HolderFrame has an instance of the Company object... Company has a HashMap of Employee objects, and has a getHashMap() method which returns the Collection of Employee objects...
so ... the JList is in the HolderFrame. I need to construct it, and place it, and i am not sure how to pull in first_name field from each Employee objet within the HashMap (provided by the Company class, which has gathered up a whole lot of Employee objects by reading in fields from a local txt file).
Please help.
[note - i am not sure if this should be in advanced or medium java or swing forum, but as it is dealing with a JList, i assume Swing].


giddee up
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You could do something like the following:


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Keith Bennett
Greenhorn

Joined: May 31, 2003
Posts: 3
I think you could also do the following:
Create an array of employee objects from the collection of employees.
Write a custom ListCellRenderer that extracts the display string from the object and passes it to the default superclass' renderer. Call JList.setCellRenderer and pass it an instance of your renderer.
The nice thing about this is that, if I'm not mistaken, getSelectedValue() will return the employee object itself; there is no need to look up the object by the displayed name.
- Keith
Jasper Vader
Ranch Hand

Joined: Jun 10, 2002
Posts: 57
brilliant stuff, i am going to have a go at implementing these ideas immeeeediately!
i have been away from the swing stuff for a bit, as i had to work on some oracle stuff, but now must develop the swing schwing.
so thanks for the replies, will let you know how i get on this afternoon.
Jasper Vader
Ranch Hand

Joined: Jun 10, 2002
Posts: 57
Hi Nate - I have not been able to get your example working yet unfortunately.
Keith - an interesting idea, am willing to try it, but i sort of dont have a concept of the implementation of it yet.
I am actually in need of a bit of practical help here. I presume bartender Nate's advice was right on the money, but it is not integrating with the code i am trying to work it into (could be the way i put it in, where i put it, or the other classes)... oh well, will keep on trying ... reading .. typing ... compiling .. running ...
cool hit me back if any good ideas to illuminate me occur anyone please.
[ June 02, 2003: Message edited by: Jasper Vader ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Please Help: JList selectable options from 'name' field from each object in a HashMap
 
Similar Threads
HashMaps and Key Selection
Toplink One Class From Two Seperate Table
Regarding Ordering the List
WSDL: Schema Duplicate cause dupicate classes
Set up Jlist