Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to Change JSpinner&JComboBox Arrows Color?

 
mahmoud saleh
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
greetings all
how to change jspinner arrows color and JComboBox Arrow Color?
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but theses methods will change the whole component not only the arrow right?
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5341284
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
mysann
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UIManager.getDefaults().put("ComboBox.buttonDarkShadow", Color.BLACK);
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"mysann", please check your private messages for an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic