Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java
38854 views
/*1* Copyright (c) 2012, 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/* @test24* @bug 4247996 426048525* @summary Test that rollover toolbar doesn't corrupt buttons26* @author Peter Zhelezniakov27* @run main bug424799628*/29import java.awt.*;30import javax.swing.*;3132public class bug4247996 {3334private static JButton button;35private static JToggleButton toogleButton;3637public static void main(String[] args) throws Exception {3839Robot robot = new Robot();40robot.setAutoDelay(50);4142UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");4344javax.swing.SwingUtilities.invokeAndWait(new Runnable() {4546public void run() {47createAndShowGUI();48}49});5051robot.waitForIdle();5253Point point = getButtonCenter();54robot.mouseMove(point.x, point.y);55robot.waitForIdle();5657checkButtonsSize();5859}6061private static void checkButtonsSize() throws Exception {62SwingUtilities.invokeAndWait(new Runnable() {6364@Override65public void run() {66if (!button.getSize().equals(toogleButton.getSize())) {67throw new RuntimeException("Button sizes are different!");68}69}70});71}7273private static Point getButtonCenter() throws Exception {74final Point[] result = new Point[1];7576SwingUtilities.invokeAndWait(new Runnable() {7778@Override79public void run() {80Point p = button.getLocationOnScreen();81Dimension size = button.getSize();82result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2);83}84});85return result[0];86}8788private static void createAndShowGUI() {89JFrame frame = new JFrame("Test");90frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);91frame.setSize(200, 200);9293JButton rButton = new JButton("Rollover");94rButton.setRolloverEnabled(true);95JToolBar nrToolbar = new JToolBar();96nrToolbar.add(rButton);97nrToolbar.remove(rButton);9899if (!rButton.isRolloverEnabled()) {100throw new Error("Failed (bug 4260485): "101+ "toolbar overrode button's rollover property");102}103104JToolBar rToolbar = new JToolBar();105rToolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);106rToolbar.add(button = new JButton("Test"));107rToolbar.add(toogleButton = new JToggleButton("Test"));108109frame.getContentPane().add(rToolbar, BorderLayout.NORTH);110frame.setVisible(true);111}112}113114115