1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6526631 27 * @summary Resizes right-oriented scroll pane 28 * @author Sergey Malenkov 29 * @library .. 30 */ 31 32 import java.awt.ComponentOrientation; 33 import java.awt.Dimension; 34 import javax.swing.JFrame; 35 import javax.swing.JScrollBar; 36 import javax.swing.JScrollPane; 37 import javax.swing.JTextArea; 38 import javax.swing.JViewport; 39 40 public class Test6526631 { 41 42 private static final int COLS = 90; 43 private static final int ROWS = 50; 44 private static final int OFFSET = 10; 45 46 public static void main(String[] args) throws Throwable { 47 SwingTest.start(Test6526631.class); 48 } 49 50 private final JScrollPane pane; 51 private final JFrame frame; 52 53 public Test6526631(JFrame frame) { 54 this.pane = new JScrollPane(new JTextArea(ROWS, COLS)); 55 this.pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 56 this.frame = frame; 57 this.frame.add(this.pane); 58 } 59 60 private void update(int offset) { 61 Dimension size = this.frame.getSize(); 62 size.width += offset; 63 this.frame.setSize(size); 64 } 65 66 public void validateFirst() { 67 validateThird(); 68 update(OFFSET); 69 } 70 71 public void validateSecond() { 72 validateThird(); 73 update(-OFFSET); 74 } 75 76 public void validateThird() { 77 JViewport viewport = this.pane.getViewport(); 78 JScrollBar scroller = this.pane.getHorizontalScrollBar(); 79 if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { 80 throw new Error("unexpected component orientation"); 81 } 82 int value = scroller.getValue(); 83 if (value != 0) { 84 throw new Error("unexpected scroll value"); 85 } 86 int extent = viewport.getExtentSize().width; 87 if (extent != scroller.getVisibleAmount()) { 88 throw new Error("unexpected visible amount"); 89 } 90 int size = viewport.getViewSize().width; 91 if (size != scroller.getMaximum()) { 92 throw new Error("unexpected maximum"); 93 } 94 int pos = size - extent - value; 95 if (pos != viewport.getViewPosition().x) { 96 throw new Error("unexpected position"); 97 } 98 } 99 }