Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JViewport/7107099/bug7107099.java
38867 views
/*1* Copyright (c) 2012, 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/* @test24@bug 710709925@summary JScrollBar does not show up even if there are enough lebgth of textstring in textField26@author Pavel Porvatov27*/2829import javax.swing.*;30import java.awt.*;3132public class bug7107099 {33private static JFrame frame;34private static JTextArea textarea;35private static JScrollPane scrollPane;3637private static int value;38private static int min;39private static int max;40private static int extent;4142public static void main(String[] args) throws Exception {4344java.awt.Robot robot = new java.awt.Robot();4546SwingUtilities.invokeAndWait(new Runnable() {47@Override48public void run() {49textarea = new JTextArea("before###1###\nbefore###2###\nbefore###3###\nbefore###4###\nbefore###5###\n");5051scrollPane = new JScrollPane(textarea);52scrollPane.setPreferredSize(new Dimension(100, 50));5354frame = new JFrame();55frame.setLayout(new BorderLayout());56frame.setSize(200, 200);57frame.add(scrollPane, BorderLayout.SOUTH);58frame.setVisible(true);59}60});6162robot.waitForIdle();6364SwingUtilities.invokeAndWait(new Runnable() {65@Override66public void run() {67BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();6869value = model.getValue();70min = model.getMinimum();71max = model.getMaximum();72extent = model.getExtent();7374// Do tricky manipulation for testing purpose75textarea.setText(null);76scrollPane.setViewportView(textarea);77textarea.setText("after###1###\nafter###1###\nafter###1###\nafter###1###\nafter###1###\n");78textarea.setCaretPosition(0);79}80});8182robot.waitForIdle();8384SwingUtilities.invokeAndWait(new Runnable() {85@Override86public void run() {87BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();8889if (value != model.getValue() ||90min != model.getMinimum() ||91max != model.getMaximum() ||92extent != model.getExtent()) {93throw new RuntimeException("Test bug7107099 failed");94}9596System.out.println("Test bug7107099 passed");9798frame.dispose();99}100});101}102}103104105