Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multi colored JComboBox  RSS feed

Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to have a JComboBox which contains a list of names.. say
"Joe", "saj", "sanjay", "ajai".... so on. Now depending on some condition i need these names to appear either in Red or in Blue.
I know that i can have my own class
MyCellRenderer which extends JLabel implements ListCellRenderer
and i can set this as the renderer for my JComboBox.
But my requirement doesnt end with this. When i made my own rendered i noticed that though the names in the dropdown list appeared in the color i wanted, yet the name that appears next to the "arrow" button is in Black. Also when i didnt have a renderer, the drop down list would automatically listen to the keys. For example if i type 's', the focus would automatically go to the first item that starts with 's'. However when i use my renderer, this doesnt happen. Help me solve these 2 problems .
Kindest regards
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!