test/jdk/javax/swing/JButton/4796987/bug4796987.java
author serb
Mon, 04 Dec 2017 16:14:29 -0800
changeset 48271 95f173494fe9
parent 47216 71c04702a3d5
child 51637 e9177e7749e7
permissions -rw-r--r--
8189656: The Windows L&F should be moved out from the shared folder Reviewed-by: prr, psadhukhan, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     1
/*
48271
95f173494fe9 8189656: The Windows L&F should be moved out from the shared folder
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     4
 *
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     8
 *
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    13
 * accompanied this code).
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    14
 *
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    18
 *
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    21
 * questions.
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    22
 */
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    23
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    24
/*
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    25
 * @test
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    26
 * @bug 4796987
48271
95f173494fe9 8189656: The Windows L&F should be moved out from the shared folder
serb
parents: 47216
diff changeset
    27
 * @requires (os.family == "windows")
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    28
 * @summary XP Only: JButton.setBorderPainted() does not work with XP L&F
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    29
 * @author Alexander Scherbatiy
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    30
 * @library ../../regtesthelpers
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 28531
diff changeset
    31
 * @library ../../../../lib/testlibrary
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 29514
diff changeset
    32
 * @modules java.desktop/com.sun.java.swing.plaf.windows
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 29514
diff changeset
    33
 *          java.desktop/sun.awt
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 28531
diff changeset
    34
 * @build jdk.testlibrary.OSInfo
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    35
 * @build Util
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    36
 * @run main bug4796987
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    37
 */
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    38
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 28531
diff changeset
    39
import jdk.testlibrary.OSInfo;
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    40
import java.awt.*;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    41
import javax.swing.*;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    42
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    43
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    44
public class bug4796987 {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    45
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    46
    private static JButton button1;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    47
    private static JButton button2;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    48
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    49
    public static void main(String[] args) throws Exception {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    50
        if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    51
                && OSInfo.getWindowsVersion() == OSInfo.WINDOWS_XP) {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    52
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    53
            testButtonBorder();
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    54
        }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    55
    }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    56
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    57
    private static void testButtonBorder() throws Exception {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    58
        Robot robot = new Robot();
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    59
        robot.setAutoDelay(50);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    60
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    61
        SwingUtilities.invokeAndWait(new Runnable() {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    62
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    63
            public void run() {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    64
                createAndShowGUI();
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    65
            }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    66
        });
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    67
29514
973914c573fc 8074092: Newly introduced unnecessary dependencies on internal API in client regtests
yan
parents: 28531
diff changeset
    68
        robot.waitForIdle();
28531
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    69
        Thread.sleep(500);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    70
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    71
        Point p1 = Util.getCenterPoint(button1);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    72
        Point p2 = Util.getCenterPoint(button2);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    73
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    74
        Color color = robot.getPixelColor(p1.x, p2.x);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    75
        for (int dx = p1.x; dx < p2.x - p1.x; dx++) {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    76
            robot.mouseMove(p1.x + dx, p1.y);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    77
            if (!color.equals(robot.getPixelColor(p1.x + dx, p1.y))) {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    78
                throw new RuntimeException("Button has border and background!");
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    79
            }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    80
        }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    81
    }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    82
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    83
    private static JButton getButton() {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    84
        JButton button = new JButton();
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    85
        button.setBorderPainted(false);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    86
        button.setFocusable(false);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    87
        return button;
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    88
    }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    89
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    90
    private static void createAndShowGUI() {
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    91
        JFrame frame = new JFrame("Test");
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    92
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    93
        frame.setSize(200, 200);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    94
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    95
        JButton button = new JButton();
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    96
        button.setBorder(null);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    97
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    98
        JPanel panel = new JPanel(new BorderLayout(50, 50));
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
    99
        panel.add(getButton(), BorderLayout.CENTER);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   100
        panel.add(button1 = getButton(), BorderLayout.WEST);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   101
        panel.add(button2 = getButton(), BorderLayout.EAST);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   102
        frame.getContentPane().add(panel);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   103
        frame.setVisible(true);
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   104
    }
d0e5475bc8ed 4796987: XP Only JButton.setBorderPainted() does not work with XP L&F
alexsch
parents:
diff changeset
   105
}