Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/ScrollPane/ScrollPaneValidateTest.java
47490 views
/*1* Copyright (c) 2018, 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*/2223/*24* @test25* @bug 819573826* @summary scroll position in ScrollPane is reset after calling validate()27* @run main ScrollPaneValidateTest28*/2930import java.awt.ScrollPane;31import java.awt.BorderLayout;32import java.awt.GridLayout;33import java.awt.Button;34import java.awt.Dimension;35import java.awt.Frame;36import java.awt.Panel;37import java.awt.Point;38import java.awt.Robot;39import java.awt.AWTException;4041public class ScrollPaneValidateTest extends Frame {42ScrollPane pane;4344public ScrollPaneValidateTest() {45setBounds(300, 300, 300, 300);46pane = new ScrollPane(ScrollPane.SCROLLBARS_NEVER);47add(pane, BorderLayout.NORTH);48pane.add(new InnerPanel());49}5051public static void main(String[] args) throws AWTException {52Robot robot = new Robot();53final ScrollPaneValidateTest obj = new ScrollPaneValidateTest();54obj.setVisible(true);5556// set to some scroll position57obj.pane.setScrollPosition(600, 200);5859// get the newly set position60Point scrollPosition = obj.pane.getScrollPosition();6162// call validate multiple times63obj.pane.validate();64robot.delay(1000);65obj.pane.validate();66robot.delay(1000);6768// compare position after calling the validate function69if(!scrollPosition.equals(obj.pane.getScrollPosition())) {70obj.dispose();71throw new RuntimeException("Scrolling position is changed in ScrollPane");72}7374obj.dispose();75return;76}7778class InnerPanel extends Panel {79public InnerPanel() {80this.setLayout(new GridLayout(2, 4));81for (int i = 1; i <= 8; i++) {82this.add(new Button("Button" + i));83}84}8586public Dimension getPreferredSize() {87return new Dimension(980, 200);88}89}90}919293