Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollPane/Test6526631.java
38838 views
/*1* Copyright (c) 2009, 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 652663126* @summary Resizes right-oriented scroll pane27* @author Sergey Malenkov28* @library ..29*/3031import java.awt.ComponentOrientation;32import java.awt.Dimension;33import javax.swing.JFrame;34import javax.swing.JScrollBar;35import javax.swing.JScrollPane;36import javax.swing.JTextArea;37import javax.swing.JViewport;3839public class Test6526631 {4041private static final int COLS = 90;42private static final int ROWS = 50;43private static final int OFFSET = 10;4445public static void main(String[] args) throws Throwable {46SwingTest.start(Test6526631.class);47}4849private final JScrollPane pane;50private final JFrame frame;5152public Test6526631(JFrame frame) {53this.pane = new JScrollPane(new JTextArea(ROWS, COLS));54this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);55this.frame = frame;56this.frame.add(this.pane);57}5859private void update(int offset) {60Dimension size = this.frame.getSize();61size.width += offset;62this.frame.setSize(size);63}6465public void validateFirst() {66validateThird();67update(OFFSET);68}6970public void validateSecond() {71validateThird();72update(-OFFSET);73}7475public void validateThird() {76JViewport viewport = this.pane.getViewport();77JScrollBar scroller = this.pane.getHorizontalScrollBar();78if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {79throw new Error("unexpected component orientation");80}81int value = scroller.getValue();82if (value != 0) {83throw new Error("unexpected scroll value");84}85int extent = viewport.getExtentSize().width;86if (extent != scroller.getVisibleAmount()) {87throw new Error("unexpected visible amount");88}89int size = viewport.getViewSize().width;90if (size != scroller.getMaximum()) {91throw new Error("unexpected maximum");92}93int pos = size - extent - value;94if (pos != viewport.getViewPosition().x) {95throw new Error("unexpected position");96}97}98}99100101