4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
authoralexsch
Wed, 17 Dec 2014 17:56:11 +0300
changeset 28531 d0e5475bc8ed
parent 28530 3d87bf5d93e8
child 28532 8b8032678def
4796987: XP Only JButton.setBorderPainted() does not work with XP L&F Reviewed-by: serb
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java
jdk/test/javax/swing/JButton/4796987/bug4796987.java
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java	Wed Dec 17 14:58:58 2014 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java	Wed Dec 17 17:56:11 2014 +0300
@@ -248,7 +248,8 @@
 
         Part part = getXPButtonType(b);
 
-        if (b.isContentAreaFilled() && xp != null) {
+        if (b.isContentAreaFilled() && b.getBorder() != null
+                && b.isBorderPainted() && xp != null) {
 
             Skin skin = xp.getSkin(b, part);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JButton/4796987/bug4796987.java	Wed Dec 17 17:56:11 2014 +0300
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4796987
+ * @summary XP Only: JButton.setBorderPainted() does not work with XP L&F
+ * @author Alexander Scherbatiy
+ * @library ../../regtesthelpers
+ * @build Util
+ * @run main bug4796987
+ */
+
+import java.awt.*;
+import javax.swing.*;
+import sun.awt.OSInfo;
+import sun.awt.SunToolkit;
+import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
+
+public class bug4796987 {
+
+    private static JButton button1;
+    private static JButton button2;
+
+    public static void main(String[] args) throws Exception {
+        if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS
+                && OSInfo.getWindowsVersion() == OSInfo.WINDOWS_XP) {
+            UIManager.setLookAndFeel(new WindowsLookAndFeel());
+            testButtonBorder();
+        }
+    }
+
+    private static void testButtonBorder() throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+        toolkit.realSync();
+        Thread.sleep(500);
+
+        Point p1 = Util.getCenterPoint(button1);
+        Point p2 = Util.getCenterPoint(button2);
+
+        Color color = robot.getPixelColor(p1.x, p2.x);
+        for (int dx = p1.x; dx < p2.x - p1.x; dx++) {
+            robot.mouseMove(p1.x + dx, p1.y);
+            if (!color.equals(robot.getPixelColor(p1.x + dx, p1.y))) {
+                throw new RuntimeException("Button has border and background!");
+            }
+        }
+    }
+
+    private static JButton getButton() {
+        JButton button = new JButton();
+        button.setBorderPainted(false);
+        button.setFocusable(false);
+        return button;
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame("Test");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setSize(200, 200);
+
+        JButton button = new JButton();
+        button.setBorder(null);
+
+        JPanel panel = new JPanel(new BorderLayout(50, 50));
+        panel.add(getButton(), BorderLayout.CENTER);
+        panel.add(button1 = getButton(), BorderLayout.WEST);
+        panel.add(button2 = getButton(), BorderLayout.EAST);
+        frame.getContentPane().add(panel);
+        frame.setVisible(true);
+    }
+}