Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... And by the way, I was also able to change color of the "arrow button" in a JComboBox the same way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic