wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes how to set the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to set the "background selection color" of a Combobox" Watch "how to set the "background selection color" of a Combobox" New topic
Author

how to set the "background selection color" of a Combobox

Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi,
the default lavender color bites with windows desktop colors. But how to set this color?
I mean the highlighting color when you scroll through the combobox.
Am hovering over the colors of good-looking eclipse guis with a colorpicker and use those colors in my gui. It seems to work.
regards Axel
[ July 15, 2003: Message edited by: Axel Janssen ]
Thomas Suer
Ranch Hand

Joined: Sep 03, 2001
Posts: 50
A good place to take a look at is
Swing Examples
For your problem you should keep an eye on the UIManager and its lookup table. For instance you could make the following invocation at startup of your app (that is before anything is displayed):

or at runtime you do the same stuff and additionally do an on the desired combo box. The last step is necessary to update the already instantiated combo box.
This should work
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hallo Thomas,
(my own findings so far...)
I've learnt now that the easiest way to change the color of the items in the combobox is to implement a own ListCellRenderer and then setRenderer (MyListCellRenderer).
Next problem is to change the color of the ScrollPane. The JList automatically embedded in the JComboBox is bound to a ScrollPane.
Now to change this ScrollPane color the only viable solutions seems to be (as you said) using UIManager.put() method.
I've sorted and printed all the keys of UIManager.getDefaults().
But what's the key to that ScrollPane inside of JComboBox? There seems to be no special key. I am going to try ScrollPane trees.
JComboBox sucks.
Axel
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
works with UIManager keys of ScrollBar.
One question: How is key of the two Arrays on top and on bottom?
Can't find that key.
Sandra Stone
Greenhorn

Joined: Jun 30, 2004
Posts: 6
Don't know if this will help, but anyway:
I was able to change the color of the "arrow-buttons" of a scrollbar in the JScrollPane this way:

Component[] comps = myScrollPane.getVerticalScrollbar().getComponents();
for(int i=0;i<comps.length;i++)
comps[i].setBackground(Color.xxx);

This colored the "arrow buttons", but not the slide itself, and not the "knob" (or "thump" or whatever it is called)

Regards...
Sandra Stone
Greenhorn

Joined: Jun 30, 2004
Posts: 6
... And by the way, I was also able to change color of the "arrow button" in a JComboBox the same way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set the "background selection color" of a Combobox
 
Similar Threads
Windows 7 not paint correctly Swing controls
Change color of JComboBox content
Color the JComboBox
Images in Debian
use CSV and add some colors