Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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 ]
 
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.
 
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.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!