Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollBar/6542335/bug6542335.java
38918 views
/*1* Copyright (c) 2010, 2011, 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 654233525@summary different behavior on knob of scroll bar between 1.4.2 and 5.026@author Alexander Potochkin27@run main bug654233528*/2930import javax.swing.*;31import javax.swing.plaf.basic.BasicScrollBarUI;32import java.awt.*;33import java.awt.event.InputEvent;3435public class bug6542335 {36private static JScrollBar sb;37private static MyScrollBarUI ui;3839public static void main(String[] args) throws Exception {40final Robot robot = new Robot();41robot.setAutoDelay(10);4243final Rectangle[] thumbBounds = new Rectangle[1];4445SwingUtilities.invokeAndWait(new Runnable() {46public void run() {47final JFrame frame = new JFrame("bug6542335");48frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4950sb = new JScrollBar(0, 0, 1, 0, 1);5152ui = new MyScrollBarUI();53sb.setUI(ui);5455sb.setPreferredSize(new Dimension(200, 17));56DefaultBoundedRangeModel rangeModel = new DefaultBoundedRangeModel();57rangeModel.setMaximum(100);58rangeModel.setMinimum(0);59rangeModel.setExtent(50);60rangeModel.setValue(50);6162sb.setModel(rangeModel);63frame.add(sb, BorderLayout.NORTH);6465frame.setSize(200, 100);66frame.setVisible(true);67}68});6970robot.waitForIdle();7172SwingUtilities.invokeAndWait(new Runnable() {73public void run() {74thumbBounds[0] = new Rectangle(ui.getThumbBounds());7576Point l = sb.getLocationOnScreen();7778robot.mouseMove(l.x + (int) (0.75 * sb.getWidth()), l.y + sb.getHeight() / 2);79robot.mousePress(InputEvent.BUTTON1_MASK);80robot.mouseRelease(InputEvent.BUTTON1_MASK);81}82});8384robot.waitForIdle();8586SwingUtilities.invokeAndWait(new Runnable() {87public void run() {88Rectangle newThumbBounds = ui.getThumbBounds();8990if (!thumbBounds[0].equals(newThumbBounds)) {91throw new RuntimeException("Test failed.\nOld bounds: " + thumbBounds[0] +92"\nNew bounds: " + newThumbBounds);93}94}95});96}9798static class MyScrollBarUI extends BasicScrollBarUI {99public Rectangle getThumbBounds() {100return super.getThumbBounds();101}102}103}104105106