Here is an example on Sun's Swing Tutorial. Althought it is part of the JComboBox tutorial, Implementing ListCellRenderer is done the exact same on both a JComboBox and a JList. That should be what you want.
Going with what Gregg said, what about using a label for the elements in the list. I think labels can hold both an image and text by nature, so if it satisfied what you needed, it might be easier than constructing something special. Plus, you may not have to create a special ListCellRenderer for labels. May just be able to add them. Have to check that tho. HTH
Chris has a point, but that can make retrieving the values a little more difficult, since you need to retrieve text typically, and not a lable. ListCellRenderer extends JLabel (which you could really extends whatever component you wanted) but for what you want, take the ListCellRenderer as is, and modify it to place your images for you, rather than adding Labels to the List that contains images and text. That way, the method to retrieve the value you need from the list doesn't change.
yeah but sucking the String out of a JLabel is as simple as getText(). Just do this: now s is your selected text value. Or if your options are always the same with the same order, you could just check the list.getSelectedIndex() and perform the apropriate action based on the int returned. That actually saves the time comparing the text strings we collected using my other method. HTH
Thanks for your help. What should I use to display 4-5 lines of text and an image? i think with a label I have only one line and it is bad to format. What do you think is the best way? Thanks in advance [ February 22, 2003: Message edited by: Kay Tracid ]
oh, well then labels are out. Maybe do something with a customized list cell renderer like what Gregg suggested. Are you sure that you need all the extra text in your list? Any way to cut it down to a single line? Without knowing what you are trying to acheive tho, the listcellrenderer sounds like the way to go...