setBackground(Color c) for JButton and JLabel

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

setBackground(Color c) for JButton and JLabel

Postby LawrenceLi » Wed Oct 03, 2007 8:37 pm

HI
I have tried the following code on Swing Designer v6.4.0 and v6.4.1(eclipse 3.2 and 3.3).

JPanel jp = new JPanel();
jp.setPreferredSize(new java.awt.Dimension(400,400));

final JButton button = new JButton("button");
button.setPreferredSize(new Dimension(111, 111));
button.setBackground(Color.BLACK);
jp.add(button);


However, non of the versions work for the button.setBackground(Color.BLACK);.It seems just the border color has been changed to black. I am wondering if this is a bug of swing designer? I tried JPanel and JRadioButton, they works for setBackground method...

Looking forward to hearing your reply.

Cheers
Peng
UBC.Canada
LawrenceLi
 
Posts: 1
Joined: Wed Oct 03, 2007 4:10 pm

Re: setBackground(Color c) for JButton and JLabel

Postby Eric Clayberg » Thu Oct 04, 2007 11:18 am

The background color of the button depends entirely on which Look & Feel you are using. Swing's standard Windows L&F emulates Windows standard behavior which sets a buttons background based on the current Windows theme. Other L&F's like Metal and Motif will show the background color.

So...no, this is not a bug. It is working exactly like expected given this "feature" of Sun's underlying Swing implementation.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest