Path: blob/master/test/jdk/javax/swing/JScrollBar/7163696/Test7163696.java
41153 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* @key headful26* @bug 716369627* @summary Tests that JScrollBar scrolls to the left28* @author Sergey Malenkov29*/3031import java.awt.Dimension;32import java.awt.Point;33import java.awt.Robot;34import java.awt.event.InputEvent;3536import javax.swing.JFrame;37import javax.swing.JScrollBar;38import javax.swing.SwingUtilities;39import javax.swing.UIManager;40import javax.swing.UIManager.LookAndFeelInfo;4142public class Test7163696 implements Runnable {4344private static final boolean AUTO = null != System.getProperty("test.src", null);4546public static void main(String[] args) throws Exception {47new Test7163696().test();48}4950private JScrollBar bar;5152private void test() throws Exception {53Robot robot = new Robot();54for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {55UIManager.setLookAndFeel(info.getClassName());5657SwingUtilities.invokeAndWait(this);58robot.waitForIdle(); // after creation59Thread.sleep(1000);6061Point point = this.bar.getLocation();62SwingUtilities.convertPointToScreen(point, this.bar);63point.x += this.bar.getWidth() >> 2;64point.y += this.bar.getHeight() >> 1;65robot.mouseMove(point.x, point.y);66robot.mousePress(InputEvent.BUTTON1_MASK);67robot.mouseRelease(InputEvent.BUTTON1_MASK);6869robot.waitForIdle(); // before validation70Thread.sleep(1000);71SwingUtilities.invokeAndWait(this);7273if (this.bar != null) {74this.bar = null; // allows to reuse the instance75if (AUTO) { // error reporting only for automatic testing76throw new Error("TEST FAILED");77}78}79}80}8182public void run() {83if (this.bar == null) {84this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);85this.bar.setPreferredSize(new Dimension(400, 20));8687JFrame frame = new JFrame();88frame.add(this.bar);89frame.pack();90frame.setVisible(true);91}92else if (40 != this.bar.getValue()) {93System.out.println("name = " + UIManager.getLookAndFeel().getName());94System.out.println("value = " + this.bar.getValue());95}96else {97SwingUtilities.getWindowAncestor(this.bar).dispose();98this.bar = null;99}100}101}102103104