Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5035820
Votes 5
Synopsis XP L&F: Button backgrounds should not be painted under the XP Look and Feel
Category java:classes_swing
Reported Against 1.4.2
Release Fixed
State 6-Fix Understood, bug
Priority: 4-Low
Related Bugs 6434931
Submit Date 22-APR-2004
Description


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 :
 customer  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) 
======================================================================
Posted Date : 2005-09-12 19:20:15.0
Work Around
N/A
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.
  xxxxx@xxxxx   2004-04-28
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.
Posted Date : 2006-03-07 04:07:27.0

Added a reference to a bug 6434931 which addresses the larger opacity/bgcolor issue.
Posted Date : 2006-06-06 22:52:09.0
Comments
  
  Include a link with my name & email   

Submitted On 28-MAY-2004
ScottWPalmwe
button.setBackground(null);
button.setOpaque(false);

works for me.


Submitted On 15-JUL-2004
ckrawchuk
The workaround posted by ScottWPalmwe doesn't work if the application is deployed to a non-XP environment, e.g. Windows 2000 (as the interior of the button is no longer painted).

This problem also occurs on Mac OSX.


Submitted On 11-OCT-2004
markusschulze
I have the same problem with my jButtons. The Problem only exist when i choose the xp style at the windows xp system administration. When i change to Windows Classic, my Buttons looks OK!


Submitted On 24-OCT-2005
I have the same problem.The solution is an look and fill of windows 2k??


Submitted On 10-JAN-2008
Bump...
It just so happens that JToogleButton seem to work correctly so it can not be that hard to fix..



PLEASE NOTE: JDK6 is formerly known as Project Mustang