I want to create a ComboBox which will be constructed using:
My custom Combobox model will contain a Map (key and the actual name for display). Thus I will need a customRenderer to dereference the actual name for display. Right ? Now, in the interface for ListCellRenderer, there is a method:
What is the type of value parameter and who actually sets it ? Thanks G
The type of value is determined by what you defined "myCustomModel" to be. It could be any object you wish. In your example, the renderer will be given the objects in your Map which will be an object. I usually use an array of objects for myCustomModel that I can call toString() on or some other getter that I use to to call like so:
If you look at the picture, I'm now able to display the strings in the combobox instead of the codes. However the selected item is now showing the code. This is due to the fact that I overrode getSelectedItem() in my custom model. e.g.
Basically the getSelectedItem is behaving like I want it to be. However the combobox should highlight the selected item & not display its code. Any comments ? Thanks G
It is the problem with the renderer. What is the value you are setting in setText()? I am facing a problem with Combobox renderer - even though I explicitly (programatically) set the selectedindex to -1 or selecteditem to null, combobox is displaying some value. How about you?