Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how to Change JSpinner&JComboBox Arrows Color?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
greetings all
how to change jspinner arrows color and JComboBox Arrow Color?
 
Sheriff
Posts: 22573
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use UIManager to set some properties.

From what I've seen in the source (javax.swing.plaf.basic package, BasicComboBoxUI, BasicSpinnerUI and BasicArrowButton) you need to play around with the following properties:

JSpinner:
UIManager.getColor("control")
UIManager.getColor("controlShadow")
UIManager.getColor("controlDkShadow")
UIManager.getColor("controlLtHighlight")

JComboBox:
UIManager.getColor("ComboBox.buttonBackground")
UIManager.getColor("ComboBox.buttonShadow")
UIManager.getColor("ComboBox.buttonDarkShadow")
UIManager.getColor("ComboBox.buttonHighlight")
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but theses methods will change the whole component not only the arrow right?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5341284
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Rob

Your solution is good for the JSpinner, but at least in the default Metal L&F, the arrow on MetalComboBoxButton is an instance of javax.swing.plaf.metal.MetalComboBoxIcon. If you look at the sources you'll see that it'll always be black for an enabled combo. These are the relevant loc, from the different classes.


The only way I could find to change the color while retaining the shape was to grab a reference to the button, get the icon, change its color and set the new icon to the button.
[ October 22, 2008: Message edited by: Darryl Burke ]
 
Rob Spoor
Sheriff
Posts: 22573
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mahmoud saleh:
but theses methods will change the whole component not only the arrow right?


Have you tried it? I haven't but I doubt that changing the colors for a combo box button will change the entire component

Also, please Be Forthright When Cross Posting To Other Sites.

Originally posted by Darryl Burke:
@Rob

Your solution is good for the JSpinner, but at least in the default Metal L&F, the arrow on MetalComboBoxButton is an instance of javax.swing.plaf.metal.MetalComboBoxIcon. If you look at the sources you'll see that it'll always be black for an enabled combo. These are the relevant loc, from the different classes.


The only way I could find to change the color while retaining the shape was to grab a reference to the button, get the icon, change its color and set the new icon to the button.

[ October 22, 2008: Message edited by: Darryl Burke ]


Well that's disappointing. Sun goes to all this trouble of using UIManager in their look&feels, then just use something as stupid as a hard coded color.

Although you can technically change that by providing a new MetalTheme, but still.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well that's disappointing. Sun goes to all this trouble of using UIManager in their look&feels, then just use something as stupid as a hard coded color.

Although you can technically change that by providing a new MetalTheme, but still.


You know, I didn't think of that. Thanks for the fish

If using the default javax.swing.plaf.metal.OceanTheme, extending that serves the purpose. Of course, overriding getControlInfo() has other implications. I've already found it also changes the color of scroll bar arrows. This was the code:
cheers, Darryl
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UIManager.getDefaults().put("ComboBox.buttonDarkShadow", Color.BLACK);
 
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"mysann", please check your private messages for an important administrative matter.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic