Menu, Button, Menuitem backgroundcolor

is there any way to change the menu , button , menuItem background color,

i know there is hastable for maintaing ui component color. and one can get the

that defaults value using UIManager.getDefaults(). which returns a hastable . and you can set the key with corresponding value for some component.

UIManager.getDefaults().put("win.menu.backgroundColor",Color.RED);

but that doesnt work.

but the following line works

UIManager.put("TableHeader.background", Color.RED);

but the following line doesnt work.

UIManager.put("ScrollBar.background", Color.RED);

i dont why swing team exposed the api , and that api doesnt works. :)

[687 byte] By [dadu420a] at [2007-10-2 15:28:47]
# 1

While it would be nice if we could expect all LookAndFeel implementations to use the same keys in the UIDefaults table, and while most implementations I've seen do make every honest effort to do so, it's not guaranteed. There's no reason why an LAF couldn't use a completely arbitrary set of keys, as long as all its associated UIs were geared for it. So... when you're trying to make changes to the UIDefaults table, it's always a good idea to check the LAF class. For example, let's pretend like we're working with the Metal look and feel (javax.swing.plaf.metal.MetalLookAndFeel class). It subclasses the javax.swing.plaf.basic.BasicLookAndFeel class, so remember to look up the heirarchy.

And we'll see that the key for the background color of a JMenuItem is "MenuItem.background", a JButton is "Button.background", and JMenu is "Menu.background". Those are the keys you set in the UIManager.

Personally, I prefer putting in a javax.swing.plaf.ColorUIResource instead of a straight java.awt.Color. But that's me.

As for why "ScrollBar.background" isn't working for you, well, it seems like it should, but you might double-check the ScrollBarUI for the LAF you're using and see if maybe it's not looking somewhere else.

Dylan.Piercea at 2007-7-13 14:49:55 > top of Java-index,Desktop,Core GUI APIs...
# 2

thanks for reply, i am using xp os, and my swing application is windows look and feel. as i have tired for changing the color of the srolllbar, menu , button, and alos menuitem color, but i failed. it doesnt works.

Do you know how to set theme for windows look and feel from java but by os

i have seen this is possible for metallookand feel , but there is no specific api for windowslookandfeel to set the theme.

dadu420a at 2007-7-13 14:49:55 > top of Java-index,Desktop,Core GUI APIs...