JDK-6463984 : Button's border is reset by WindowsButtonListener
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-08-25
  • Updated: 2011-02-16
  • Resolved: 2006-09-06
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
After I call JButton#setBorder(), WindowsButtonListener set it back to the default border.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the sample code I posted and run. You'll get the result from stderr.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
With JDK 1.5.0_06 I got this result:

border: null
preferredSize: java.awt.Dimension[width=23,height=13]

ACTUAL -
With JDK 1.5.0_08, I got this result:

border: com.sun.java.swing.plaf.windows.XPStyle$XPEmptyBorder@8ed465
preferredSize: java.awt.Dimension[width=55,height=21]



REPRODUCIBILITY :
This bug can be reproduced always.

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

public class Test
{
    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        
        final JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        final JButton button = new JButton("Test");
        button.setBorder(null);
//      button.setBorderPainted(false);
//      button.setContentAreaFilled(false);
//      button.setFocusable(false);
//      button.setFocusPainted(false);
//      button.setOpaque(false);
//      button.setMargin(new Insets(0, 0, 0, 0));
        frame.getContentPane().add(button);
        
        frame.pack();
        frame.setVisible(true);
        
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                System.err.println("border: " + button.getBorder());
                System.err.println("preferredSize: " + button.getPreferredSize());
            }
        });
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Create a class derived from JButton and override setBorder to do nothing.

Release Regression From : 5.0u6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION Duplicate of 6349010.
06-09-2006

EVALUATION This was caused by the backport of Mustang Windows Look and Feel fixes, 5106661. With the recent backport of 6349010 this should be fixed.
01-09-2006