JDK-4880747 : XP L&F: REGRESSION: setBackground on JButton sets border color in Windows XP
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-06-18
  • Updated: 2003-06-19
  • Resolved: 2003-06-19
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

Name: rmT116609			Date: 06/18/2003


FULL PRODUCT VERSION :
[c:\java\work]java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

FULL OS VERSION :
4NT  4.01A   Windows XP 5.1

A DESCRIPTION OF THE PROBLEM :
When using the XP Look-and-Feel in Java 1.4.2, setBackground() no longer sets the background color of the button.  Instead, it sets an edge color.  This only happens when using the XP Look-and-Feel; setBackground() works correctly when the -Dswing.noxp flag is used.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program shown below.  For example:

\j2sdk1.4.1_02\bin\java ButtonTest
\j2sdk1.4.2\bin\java ButtonTest
\j2sdk1.4.2\bin\java -Dswing.noxp ButtonTest


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This program should show the buttons as fully red, yellow and green.  This works correctly in 1.4.1_02 and in 1.4.2 when using -Dswing.noxp.
ACTUAL -
In 1.4.2 using the XP Look-and-Feel, the buttons only show a band of color around the edges.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class ButtonTest extends JFrame
{
  public ButtonTest()
  {
    super("ButtonTest");

try { javax.swing.UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel()); }
catch(Exception e){e.printStackTrace();}

    Container pane = getContentPane();
    pane.setLayout(new GridLayout(0,1,10,10));

    JButton red = new JButton("Red");
    red.setBackground(Color.RED);
    pane.add(red);

    JButton yellow = new JButton("Yellow");
    yellow.setBackground(Color.YELLOW);
    pane.add(yellow);

    JButton green = new JButton("Green");
    green.setBackground(Color.GREEN);
    pane.add(green);
  }

  public static void main(String args[])
  {
    JFrame frame = new ButtonTest();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(120, 180);
    frame.setVisible(true);
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None.  The -Dswing.noxp flag isn't an option because we generally want the XP Look-and-Feel.

Release Regression From : 1.4.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 188492) 
======================================================================

Comments
WORK AROUND button.setContentAreaFilled(false); button.setOpaque(true); Note: the order of these two calls is important. ###@###.### 2003-06-19
19-06-2003

EVALUATION Changing the appearance of a button can always cause conflicts with the current L&F implementation. The Windows L&F for Swing tries to be as close as possible to the native display. On XP, we use the built-in bitmap resources for the buttons. These can not be colorized, just like in the native API. You should call setContentAreaFilled(false) on the button to avoid having the L&F paint its decorations. This has the side effect that the button's opaque property is set to false, so you need to follow that call with a call to setOpaque(true). This is not a bug and will be closed. ###@###.### 2003-06-19
19-06-2003