JDK-4881191 : XP L&F: button border painted as a background image
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-06-19
  • Updated: 2003-06-19
  • Resolved: 2003-06-19
Related Reports
Relates :  
Relates :  
Description

Name: rmT116609			Date: 06/19/2003


FULL PRODUCT 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 :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The new Windows XP L&F uses a background image to paint the button border instead of a real border.  This causes a problem with any code that sets a different border on the button or that wants a flat button look, since both the XP border and the manually set border is applied.  Additionally, the text for the button no longer fits because the empty border is replaced by the defined border.

It would make much more sense to implement a Border that paints the XP L&F border so that it can be easily replaced and existing code will work as expected.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a button and set a different border on it (while using 1.4.2-beta and Windows XP L&F).
eg:

JButton btn = new JButton("date");
btn.setBorder(BorderFactory.createLineBorder(Color.red));



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected the button to be drawn with a single red line border.
ACTUAL -
The button was drawn with a red line border surrounding the XP button border and the text overlapping the XP button border making it hard to read.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class Test {

    public static final void main(String[] args) {
        JFrame frame = new JFrame();
        JButton btn = new JButton("date");
        btn.setBorder(BorderFactory.createLineBorder(Color.red));
        frame.getContentPane().add(btn);
        frame.pack();
        frame.show();
    }
}   
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Add btn.setContentFilled(false) to hide the border on XP.  This is very non-obvious though.
(Review ID: 188406) 
======================================================================

Comments
WORK AROUND button.setContentAreaFilled(false); ###@###.### 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. The visual border in XP's default style is part of this bitmap and can not programmatically be extracted or removed from the rest of the image. You should call setContentAreaFilled(false) on the button to avoid having the L&F paint its decorations. This is not a bug and will be closed. See also bug 4881191 (which was also closed for the same reason). ###@###.### 2003-06-19
19-06-2003