Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi colored JComboBox

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Saj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic