• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Color in JComboBox

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to have a JComboBox with a different background and foreground for the selected item, you can do this :
UIManager.put("ComboBox.selectionBackground",Color.red);
UIManager.put("ComboBox.selectionForeground",Color.white);
UIManager.put("ComboBox.background",Color.white);
comboBox.updateUI();

Of course, you can combine this with a different Look And Feel
for a better effect !
Ana.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 [email protected]

jessie
thanks
reply
    Bookmark Topic Watch Topic
  • New Topic