This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi colored JComboBox

Sajee Joseph
Ranch Hand
Posts: 200
  • 0
  • 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
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic