aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to Change JSpinner&JComboBox Arrows Color? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to Change JSpinner&JComboBox Arrows Color?" Watch "how to Change JSpinner&JComboBox Arrows Color?" New topic
Author

how to Change JSpinner&JComboBox Arrows Color?

mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
greetings all
how to change jspinner arrows color and JComboBox Arrow Color?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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")


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
but theses methods will change the whole component not only the arrow right?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4545
    
    5

Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5341284


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4545
    
    5

@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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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

Joined: May 03, 2008
Posts: 4545
    
    5

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

Joined: Dec 11, 2008
Posts: 1
UIManager.getDefaults().put("ComboBox.buttonDarkShadow", Color.BLACK);
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

"mysann", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: how to Change JSpinner&JComboBox Arrows Color?