1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @key headful 27 * @bug 7163696 28 * @summary Tests that JScrollBar scrolls to the left 29 * @author Sergey Malenkov 30 */ 31 32 import java.awt.Dimension; 33 import java.awt.Point; 34 import java.awt.Robot; 35 import java.awt.event.InputEvent; 36 37 import javax.swing.JFrame; 38 import javax.swing.JScrollBar; 39 import javax.swing.SwingUtilities; 40 import javax.swing.UIManager; 41 import javax.swing.UIManager.LookAndFeelInfo; 42 43 public class Test7163696 implements Runnable { 44 45 private static final boolean AUTO = null != System.getProperty("test.src", null); 46 47 public static void main(String[] args) throws Exception { 48 new Test7163696().test(); 49 } 50 51 private JScrollBar bar; 52 53 private void test() throws Exception { 54 Robot robot = new Robot(); 55 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 56 UIManager.setLookAndFeel(info.getClassName()); 57 58 SwingUtilities.invokeAndWait(this); 59 robot.waitForIdle(); // after creation 60 Thread.sleep(1000); 61 62 Point point = this.bar.getLocation(); 63 SwingUtilities.convertPointToScreen(point, this.bar); 64 point.x += this.bar.getWidth() >> 2; 65 point.y += this.bar.getHeight() >> 1; 66 robot.mouseMove(point.x, point.y); 67 robot.mousePress(InputEvent.BUTTON1_MASK); 68 robot.mouseRelease(InputEvent.BUTTON1_MASK); 69 70 robot.waitForIdle(); // before validation 71 Thread.sleep(1000); 72 SwingUtilities.invokeAndWait(this); 73 74 if (this.bar != null) { 75 this.bar = null; // allows to reuse the instance 76 if (AUTO) { // error reporting only for automatic testing 77 throw new Error("TEST FAILED"); 78 } 79 } 80 } 81 } 82 83 public void run() { 84 if (this.bar == null) { 85 this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100); 86 this.bar.setPreferredSize(new Dimension(400, 20)); 87 88 JFrame frame = new JFrame(); 89 frame.add(this.bar); 90 frame.pack(); 91 frame.setVisible(true); 92 } 93 else if (40 != this.bar.getValue()) { 94 System.out.println("name = " + UIManager.getLookAndFeel().getName()); 95 System.out.println("value = " + this.bar.getValue()); 96 } 97 else { 98 SwingUtilities.getWindowAncestor(this.bar).dispose(); 99 this.bar = null; 100 } 101 } 102 }