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 sun.awt.SunToolkit;
  33 
  34 import java.awt.Dimension;
  35 import java.awt.Point;
  36 import java.awt.Robot;
  37 import java.awt.Toolkit;
  38 import java.awt.event.InputEvent;
  39 
  40 import javax.swing.JFrame;
  41 import javax.swing.JScrollBar;
  42 import javax.swing.SwingUtilities;
  43 import javax.swing.UIManager;
  44 import javax.swing.UIManager.LookAndFeelInfo;
  45 
  46 public class Test7163696 implements Runnable {
  47 
  48     private static final boolean AUTO = null != System.getProperty("test.src", null);
  49 
  50     public static void main(String[] args) throws Exception {
  51         new Test7163696().test();
  52     }
  53 
  54     private JScrollBar bar;
  55 
  56     private void test() throws Exception {
  57         Robot robot = new Robot();
  58         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  59         for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  60             UIManager.setLookAndFeel(info.getClassName());
  61 
  62             SwingUtilities.invokeAndWait(this);
  63             toolkit.realSync(); // after creation
  64             Thread.sleep(1000);
  65 
  66             Point point = this.bar.getLocation();
  67             SwingUtilities.convertPointToScreen(point, this.bar);
  68             point.x += this.bar.getWidth() >> 2;
  69             point.y += this.bar.getHeight() >> 1;
  70             robot.mouseMove(point.x, point.y);
  71             robot.mousePress(InputEvent.BUTTON1_MASK);
  72             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  73 
  74             toolkit.realSync(); // before validation
  75             Thread.sleep(1000);
  76             SwingUtilities.invokeAndWait(this);
  77 
  78             if (this.bar != null) {
  79                 this.bar = null; // allows to reuse the instance
  80                 if (AUTO) { // error reporting only for automatic testing
  81                     throw new Error("TEST FAILED");
  82                 }
  83             }
  84         }
  85     }
  86 
  87     public void run() {
  88         if (this.bar == null) {
  89             this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);
  90             this.bar.setPreferredSize(new Dimension(400, 20));
  91 
  92             JFrame frame = new JFrame();
  93             frame.add(this.bar);
  94             frame.pack();
  95             frame.setVisible(true);
  96         }
  97         else if (40 != this.bar.getValue()) {
  98             System.out.println("name = " + UIManager.getLookAndFeel().getName());
  99             System.out.println("value = " + this.bar.getValue());
 100         }
 101         else {
 102             SwingUtilities.getWindowAncestor(this.bar).dispose();
 103             this.bar = null;
 104         }
 105     }
 106 }