United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5035820 : XP L&F: Button backgrounds should not be painted under the XP Look and Feel

Details
Type:
Bug
Submit Date:
2004-04-22
Status:
Open
Updated Date:
2011-01-20
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.4.2
Targeted Versions:

Related Reports
Relates:

Sub Tasks

Description
Name: gm110360			Date: 04/21/2004


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Apparently the XP L&F buttons use Windows system bitmaps to paint the rounded buttons.  The only problem with this is that if you are going to paint rounded corner buttons, don't paint a rectangular background first - especially if the background color is ignored anyway. All of our application panels use a blue shaded background color.  Once we upgraded to 1.4.2 our buttons looked horrible - we can't ship with this look.  The rounded corner XP buttons on our blue backgrounds all have a gray rectangular border - the button background color.
I have seen forums discussing the problem of button background colors now being ignored under XP look and feel - to me that is a different issue.  Whether the XP button is a different color or not, the background should not be drawn as a rectangle if the button has rounded corners.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Under Windows XP using the XP L&F, create a JPanel and add a number of buttons to it.  Set the background color of the JPanel to something other than default gray - like blue.  Start the app and look at the buttons.  The buttons look horrible.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect a rounded corner button to draw a rounded corner background, an oval button to draw an oval background, and a triangle button to draw a triangle background.
ACTUAL -
A rounded corner button draws a rectangular background.  Since the background color is ignored anyway under the XP L&F - why draw it, especially as a rectangle.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;

public class Test {
    public static void main(String[] args) { 
        JFrame jf = new JFrame();
	    JPanel p = new JPanel();
	    p.setBackground(Color.BLUE);
	    p.add(new JButton("One"));
	    p.add(new JButton("Two"));
	    p.add(new JButton("Three"));
	    jf.getContentPane().add(p, BorderLayout.CENTER);
        jf.show();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have none at this time although I have tried.  I don't want to litter my code with cases for various OS versions, L&Fs, skins, etc.  That reminds me of another language where I used commands like #ifdef.  I tried a number of things but the code gets ugly fast especially if you allow the user to change the L&F at runtime.  I don't want to extend BasicButtonUI and try to set it at the right time based on the L&F.  I don't want to override paintComponent and do the same tests to paint the background or not.  I tried the suggestion I saw from one developer at Sun to setContentAreaFilled(false) and opaque(true).  That just left me with a flat rectangular button with no border.  And if the user has their XP system set to the Classic look, I have no way to know and all of my workarounds are out the window.
As new L&Fs become more invasive and complex it becomes less and less desirable to extend Swing components to fix or override behavior.  Work arounds that work now may not work for the ??? L&F in the future.  In a way you are becoming the "shared code group" for other companies.  If I need a bug fix there is really only one place to fix it and that is at the source.
Please respond as soon as you can because seemingly little bugs like this effect major decisions that we must make regarding our future direction.
(Incident Review ID: 209061) 
======================================================================

                                    

Comments
WORK AROUND

To set opaque false or to set manually background of buttons
                                     
2011-01-20
EVALUATION

Added a reference to a bug 6434931 which addresses the larger opacity/bgcolor issue.
                                     
2006-06-06
EVALUATION

I just tested this again. This does indeed happen because of the skin painting.  The solution is to make the button be non-opaque by default. However, this may have performance and backward compatibility problems.
                                     
2006-03-07
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-09-25
EVALUATION

The button background is not ignored, it shows wherever the current style
doesn't cover it with a bitmap image. We may need to change inheritance and/or
opacity for buttons on XP.
###@###.### 2004-04-28
                                     
2004-04-28



Hardware and Software, Engineered to Work Together