Path: blob/master/test/jdk/javax/swing/JButton/4796987/bug4796987.java
41153 views
/*1* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 479698726* @key headful27* @requires (os.family == "windows")28* @summary XP Only: JButton.setBorderPainted() does not work with XP L&F29* @author Alexander Scherbatiy30* @library ../../regtesthelpers31* @library /test/lib32* @modules java.desktop/com.sun.java.swing.plaf.windows33* java.desktop/sun.awt34* @build jdk.test.lib.OSVersion jdk.test.lib.Platform35* @build Util36* @run main bug479698737*/3839import jdk.test.lib.Platform;40import jdk.test.lib.OSVersion;41import java.awt.*;42import javax.swing.*;43import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;4445public class bug4796987 {4647private static JButton button1;48private static JButton button2;49private static JFrame frame;5051public static void main(String[] args) throws Exception {52try {53if (Platform.isWindows()54&& OSVersion.current().equals(OSVersion.WINDOWS_XP)) {55UIManager.setLookAndFeel(new WindowsLookAndFeel());56testButtonBorder();57}58} finally {59if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());60}61}6263private static void testButtonBorder() throws Exception {64Robot robot = new Robot();65robot.setAutoDelay(50);6667SwingUtilities.invokeAndWait(new Runnable() {6869public void run() {70createAndShowGUI();71}72});7374robot.waitForIdle();75Thread.sleep(500);7677Point p1 = Util.getCenterPoint(button1);78Point p2 = Util.getCenterPoint(button2);7980Color color = robot.getPixelColor(p1.x, p2.x);81for (int dx = p1.x; dx < p2.x - p1.x; dx++) {82robot.mouseMove(p1.x + dx, p1.y);83if (!color.equals(robot.getPixelColor(p1.x + dx, p1.y))) {84throw new RuntimeException("Button has border and background!");85}86}87}8889private static JButton getButton() {90JButton button = new JButton();91button.setBorderPainted(false);92button.setFocusable(false);93return button;94}9596private static void createAndShowGUI() {97frame = new JFrame("Test");98frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);99frame.setSize(200, 200);100101JButton button = new JButton();102button.setBorder(null);103104JPanel panel = new JPanel(new BorderLayout(50, 50));105panel.add(getButton(), BorderLayout.CENTER);106panel.add(button1 = getButton(), BorderLayout.WEST);107panel.add(button2 = getButton(), BorderLayout.EAST);108frame.getContentPane().add(panel);109frame.setVisible(true);110}111}112113114