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].
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
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.
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 ]
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop