Sets the renderer that paints the list items and the item selected from the list in the JComboBox field. The renderer is used if the JComboBox is not editable. If it is editable, the editor is used to render and edit the selected item.
The default renderer displays a string or an icon. Other renderers can handle graphic images and composite items.
To display the selected item, aRenderer.getListCellRendererComponent is called, passing the list object and an index of -1.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Call setBackground(...) with a value dependent on the isSelected argument.
Karthik Shiraly wrote:This doesn't seem to be all that simple. It behaves differently in different look and feels - in Metal, the background color is simply ignored for the body but used for the arrow(??) and the list, while in Windows system look and feel, it works fine.
What L&F are you using - what's the OS?
In my Win7 system, I had to just setBackground of combobox to pink; it worked as expected even with a custom renderer and regardless of focus. I didn't need to set background of renderer at all.
But it worked very differently in other L&Fs.
Michael Dunn wrote:> so I'm using a custom renderer to display the name of the Customer
instead of using a renderer, create a Customer class where you override
toString() to return the customer's name, then just read the db data into
Customer objects and add them to the comboBox (which will display only
the customer's name).
Consider Paul's rocket mass heater. |