Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollBar/7163696/Test7163696.java
38918 views
/*1* Copyright (c) 2013, 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 716369626* @summary Tests that JScrollBar scrolls to the left27* @author Sergey Malenkov28*/2930import java.awt.Dimension;31import java.awt.Point;32import java.awt.Robot;33import java.awt.event.InputEvent;3435import javax.swing.JFrame;36import javax.swing.JScrollBar;37import javax.swing.SwingUtilities;38import javax.swing.UIManager;39import javax.swing.UIManager.LookAndFeelInfo;4041public class Test7163696 implements Runnable {4243private static final boolean AUTO = null != System.getProperty("test.src", null);4445public static void main(String[] args) throws Exception {46new Test7163696().test();47}4849private JScrollBar bar;5051private void test() throws Exception {52Robot robot = new Robot();53for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {54UIManager.setLookAndFeel(info.getClassName());5556SwingUtilities.invokeAndWait(this);57robot.waitForIdle(); // after creation58Thread.sleep(1000);5960Point point = this.bar.getLocation();61SwingUtilities.convertPointToScreen(point, this.bar);62point.x += this.bar.getWidth() >> 2;63point.y += this.bar.getHeight() >> 1;64robot.mouseMove(point.x, point.y);65robot.mousePress(InputEvent.BUTTON1_MASK);66robot.mouseRelease(InputEvent.BUTTON1_MASK);6768robot.waitForIdle(); // before validation69Thread.sleep(1000);70SwingUtilities.invokeAndWait(this);7172if (this.bar != null) {73this.bar = null; // allows to reuse the instance74if (AUTO) { // error reporting only for automatic testing75throw new Error("TEST FAILED");76}77}78}79}8081public void run() {82if (this.bar == null) {83this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);84this.bar.setPreferredSize(new Dimension(400, 20));8586JFrame frame = new JFrame();87frame.add(this.bar);88frame.pack();89frame.setVisible(true);90}91else if (40 != this.bar.getValue()) {92System.out.println("name = " + UIManager.getLookAndFeel().getName());93System.out.println("value = " + this.bar.getValue());94}95else {96SwingUtilities.getWindowAncestor(this.bar).dispose();97this.bar = null;98}99}100}101102103