This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Color for Button in Windows look and feel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Color for Button in Windows look and feel" Watch "Color for Button in Windows look and feel" New topic
Author

Color for Button in Windows look and feel

Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Hi,

I have a swing application. The look and feel for that application is WINDOWS LOOK AND FEEL. I have a JButton in it. When i try to set the color for JButton using

JButton button = new JButton("OK");
button.setBackground(Color.GREEN);

But i am not getting the color in Button. Same code works if i just change the look and feel to defalt java look and feel.


Karthick D V
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
JButton button = new JButton("OK");
button.setBackground(Color.GREEN);
button.setContentAreaFilled(false);
button.setOpaque(true);
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Thanks that worked.. But this button alone looks some what different when compared to all other buttons in this panel...

This button looks like java look and feel

and all other button looks like windows look and feel...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4880747

scroll down to 'Evaluation'
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Thanks a lot!! I learnt it today!! I posted one more query for JButton in Windows Look and Feel.. The prob is when i add mnemonic to a button I am not getting '_' below that particulat letter in the Button name. Is there any way to get the '_' in Button Name using windows look and feel.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if xp, the default for mnemonics is 'hidden' (I think)

control panel/display/appearance/effects
and uncheck 'Hide underlined letters......'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Color for Button in Windows look and feel