Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/JScrollPaneOverlapping.java
47626 views
/*1* Copyright (c) 2014, 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@summary Overlapping test for javax.swing.JScrollPane43@author [email protected]: area=awt.mixing44@library ../../regtesthelpers45@build Util46@run main JScrollPaneOverlapping47*/48public class JScrollPaneOverlapping extends OverlappingTestBase {4950// {testEmbeddedFrame = true;}5152private boolean horizontalClicked = false;53private boolean verticalClicked = false;54private Point hLoc;55private Point vLoc;5657private JFrame f;58private JPanel p;59private JScrollPane scrollPane;6061protected void prepareControls() {6263f = new JFrame("JScrollPane");64f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);65f.setSize(120, 120);6667p = new JPanel(new GridLayout(0, 1));6869scrollPane = new JScrollPane(p);70scrollPane.setPreferredSize(new Dimension(300,300));71scrollPane.setHorizontalScrollBarPolicy(72JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);73scrollPane.setVerticalScrollBarPolicy(74JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);7576scrollPane.getHorizontalScrollBar().setValue(1);77scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {7879public void adjustmentValueChanged(AdjustmentEvent e) {80horizontalClicked = true;81}82});8384scrollPane.getVerticalScrollBar().setValue(1);85scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {8687public void adjustmentValueChanged(AdjustmentEvent e) {88verticalClicked = true;89}90});9192f.getContentPane().add(scrollPane);93f.setVisible(true);94propagateAWTControls(p);95// JButton b = new JButton("Space extender");96// b.setPreferredSize(new Dimension(150,150));97// p.add( b );9899//b.requestFocus(); // to change the look of AWT component, especially Choice100}101102@Override103protected boolean performTest() {104// run robot105Robot robot = Util.createRobot();106robot.setAutoDelay(ROBOT_DELAY);107108try {109SwingUtilities.invokeAndWait(new Runnable() {110public void run() {111hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();112vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();113}114});115} catch (Exception e) {116}117hLoc.translate(2, 2);118vLoc.translate(2, 2);119120clickAndBlink(robot, hLoc, false);121clickAndBlink(robot, vLoc, false);122123return horizontalClicked && verticalClicked;124}125126// this strange plumbing stuff is required due to "Standard Test Machinery" in base class127public static void main(String args[]) throws InterruptedException {128instance = new JScrollPaneOverlapping();129OverlappingTestBase.doMain(args);130}131}132133134