1 /* 2 * Copyright (c) 2014, 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 import java.awt.Dimension; 26 import java.awt.GridLayout; 27 import java.awt.Point; 28 import java.awt.Robot; 29 import java.awt.event.AdjustmentEvent; 30 import java.awt.event.AdjustmentListener; 31 import javax.swing.JFrame; 32 import javax.swing.JPanel; 33 import javax.swing.JScrollPane; 34 import javax.swing.SwingUtilities; 35 import test.java.awt.regtesthelpers.Util; 36 37 /** 38 * AWT/Swing overlapping test for {@link javax.swing.JScrollPane } component. 39 * <p>See base class for test info. 40 */ 41 /* 42 @test 43 @summary Overlapping test for javax.swing.JScrollPane 44 @author sergey.grinev@oracle.com: area=awt.mixing 45 @library ../../regtesthelpers 46 @build Util 47 @run main JScrollPaneOverlapping 48 */ 49 public class JScrollPaneOverlapping extends OverlappingTestBase { 50 51 // {testEmbeddedFrame = true;} 52 53 private boolean horizontalClicked = false; 54 private boolean verticalClicked = false; 55 private Point hLoc; 56 private Point vLoc; 57 58 private JFrame f; 59 private JPanel p; 60 private JScrollPane scrollPane; 61 62 protected void prepareControls() { 63 64 f = new JFrame("JScrollPane"); 65 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 66 f.setSize(120, 120); 67 68 p = new JPanel(new GridLayout(0, 1)); 69 70 scrollPane = new JScrollPane(p); 71 scrollPane.setPreferredSize(new Dimension(300,300)); 72 scrollPane.setHorizontalScrollBarPolicy( 73 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 74 scrollPane.setVerticalScrollBarPolicy( 75 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 76 77 scrollPane.getHorizontalScrollBar().setValue(1); 78 scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() { 79 80 public void adjustmentValueChanged(AdjustmentEvent e) { 81 horizontalClicked = true; 82 } 83 }); 84 85 scrollPane.getVerticalScrollBar().setValue(1); 86 scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { 87 88 public void adjustmentValueChanged(AdjustmentEvent e) { 89 verticalClicked = true; 90 } 91 }); 92 93 f.getContentPane().add(scrollPane); 94 f.setVisible(true); 95 propagateAWTControls(p); 96 // JButton b = new JButton("Space extender"); 97 // b.setPreferredSize(new Dimension(150,150)); 98 // p.add( b ); 99 100 //b.requestFocus(); // to change the look of AWT component, especially Choice 101 } 102 103 @Override 104 protected boolean performTest() { 105 // run robot 106 Robot robot = Util.createRobot(); 107 robot.setAutoDelay(ROBOT_DELAY); 108 109 try { 110 SwingUtilities.invokeAndWait(new Runnable() { 111 public void run() { 112 hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen(); 113 vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen(); 114 } 115 }); 116 } catch (Exception e) { 117 } 118 hLoc.translate(2, 2); 119 vLoc.translate(2, 2); 120 121 clickAndBlink(robot, hLoc, false); 122 clickAndBlink(robot, vLoc, false); 123 124 return horizontalClicked && verticalClicked; 125 } 126 127 // this strange plumbing stuff is required due to "Standard Test Machinery" in base class 128 public static void main(String args[]) throws InterruptedException { 129 instance = new JScrollPaneOverlapping(); 130 OverlappingTestBase.doMain(args); 131 } 132 }