Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JScrollPaneOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2016, 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*/222324import java.awt.Dimension;25import java.awt.GridLayout;26import java.awt.Point;27import java.awt.Robot;28import java.awt.event.AdjustmentEvent;29import java.awt.event.AdjustmentListener;30import javax.swing.JFrame;31import javax.swing.JPanel;32import javax.swing.JScrollPane;33import javax.swing.SwingUtilities;34import test.java.awt.regtesthelpers.Util;3536/**37* AWT/Swing overlapping test for {@link javax.swing.JScrollPane } component.38* <p>See base class for test info.39*/40/*41* @test42* @key headful43* @summary Overlapping test for javax.swing.JScrollPane44* @author [email protected]: area=awt.mixing45* @library /java/awt/patchlib ../../regtesthelpers46* @modules java.desktop/sun.awt47* java.desktop/java.awt.peer48* @build java.desktop/java.awt.Helper49* @build Util50* @run main JScrollPaneOverlapping51*/52public class JScrollPaneOverlapping extends OverlappingTestBase {5354// {testEmbeddedFrame = true;}5556private boolean horizontalClicked = false;57private boolean verticalClicked = false;58private Point hLoc;59private Point vLoc;6061private JFrame f;62private JPanel p;63private JScrollPane scrollPane;6465protected void prepareControls() {6667f = new JFrame("JScrollPane");68f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);69f.setSize(120, 120);7071p = new JPanel(new GridLayout(0, 1));7273scrollPane = new JScrollPane(p);74scrollPane.setPreferredSize(new Dimension(300,300));75scrollPane.setHorizontalScrollBarPolicy(76JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);77scrollPane.setVerticalScrollBarPolicy(78JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);7980scrollPane.getHorizontalScrollBar().setValue(1);81scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {8283public void adjustmentValueChanged(AdjustmentEvent e) {84horizontalClicked = true;85}86});8788scrollPane.getVerticalScrollBar().setValue(1);89scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {9091public void adjustmentValueChanged(AdjustmentEvent e) {92verticalClicked = true;93}94});9596f.getContentPane().add(scrollPane);97f.setVisible(true);98propagateAWTControls(p);99// JButton b = new JButton("Space extender");100// b.setPreferredSize(new Dimension(150,150));101// p.add( b );102103//b.requestFocus(); // to change the look of AWT component, especially Choice104}105106@Override107protected boolean performTest() {108// run robot109Robot robot = Util.createRobot();110robot.setAutoDelay(ROBOT_DELAY);111112try {113SwingUtilities.invokeAndWait(new Runnable() {114public void run() {115hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();116vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();117}118});119} catch (Exception e) {120}121hLoc.translate(2, 2);122vLoc.translate(2, 2);123124clickAndBlink(robot, hLoc, false);125clickAndBlink(robot, vLoc, false);126127return horizontalClicked && verticalClicked;128}129130// this strange plumbing stuff is required due to "Standard Test Machinery" in base class131public static void main(String args[]) throws InterruptedException {132instance = new JScrollPaneOverlapping();133OverlappingTestBase.doMain(args);134}135}136137138