File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Color in JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Color in JComboBox" Watch "Color in JComboBox" New topic

Color in JComboBox

Ranch Hand

Joined: May 02, 2001
Posts: 48
I'm using Swing in Java 1.2. I need to be able to change the color of the highlighting when choosing an item in a JComboBox. Is there anyway to do this? I have looked in the API specifications, but either it's not there, or I'm missing it. Any pointers would be helpful.
Thank you,
April Johnson
Software Engineer
Angela Lamb
Ranch Hand

Joined: Feb 22, 2001
Posts: 156
You'll need to create a custom cell renderer for the JComboBox, then use the setRenderer(ListCellRenderer aRenderer) method to use it. Here is the example class shown in the API for ListCellRenderer that changes the select colors:
Ana Mihailescu

Joined: Apr 26, 2001
Posts: 29
If you want to have a JComboBox with a different background and foreground for the selected item, you can do this :

Of course, you can combine this with a different Look And Feel
for a better effect !
jiaonu wang

Joined: May 01, 2001
Posts: 5
Hi, Ana
Do you have examples about creating gray-scaled java swing Applet? or better examples about LookAndFeel, I need the whole applet is gray-scaled, not only the three primary colors. You can reply to me at

I agree. Here's the link:
subject: Color in JComboBox
It's not a secret anymore!