Path: blob/master/test/jdk/javax/swing/JScrollPane/Test6526631.java
41149 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* @key headful26* @bug 652663127* @summary Resizes right-oriented scroll pane28* @author Sergey Malenkov29* @library ..30*/3132import java.awt.ComponentOrientation;33import java.awt.Dimension;34import javax.swing.JFrame;35import javax.swing.JScrollBar;36import javax.swing.JScrollPane;37import javax.swing.JTextArea;38import javax.swing.JViewport;3940public class Test6526631 {4142private static final int COLS = 90;43private static final int ROWS = 50;44private static final int OFFSET = 10;4546public static void main(String[] args) throws Throwable {47SwingTest.start(Test6526631.class);48}4950private final JScrollPane pane;51private final JFrame frame;5253public Test6526631(JFrame frame) {54this.pane = new JScrollPane(new JTextArea(ROWS, COLS));55this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);56this.frame = frame;57this.frame.add(this.pane);58}5960private void update(int offset) {61Dimension size = this.frame.getSize();62size.width += offset;63this.frame.setSize(size);64}6566public void validateFirst() {67validateThird();68update(OFFSET);69}7071public void validateSecond() {72validateThird();73update(-OFFSET);74}7576public void validateThird() {77JViewport viewport = this.pane.getViewport();78JScrollBar scroller = this.pane.getHorizontalScrollBar();79if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {80throw new Error("unexpected component orientation");81}82int value = scroller.getValue();83if (value != 0) {84throw new Error("unexpected scroll value");85}86int extent = viewport.getExtentSize().width;87if (extent != scroller.getVisibleAmount()) {88throw new Error("unexpected visible amount");89}90int size = viewport.getViewSize().width;91if (size != scroller.getMaximum()) {92throw new Error("unexpected maximum");93}94int pos = size - extent - value;95if (pos != viewport.getViewPosition().x) {96throw new Error("unexpected position");97}98}99}100101102