Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollPane/6274267/bug6274267.java
38918 views
/*1* Copyright (c) 2011, 2014, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* @test26@bug 627426727@summary Checks that ScrollPaneLayout properly calculates preferred28layout size.29@author Mikhail Lapshin30@run main bug627426731*/3233import javax.swing.*;34import java.awt.*;3536public class bug6274267 {37private JFrame frame;38private Component left;3940public static void main(String[] args) throws Exception {41final bug6274267 test = new bug6274267();42Robot robot = new Robot();43try {44SwingUtilities.invokeAndWait(new Runnable() {45public void run() {46test.setupUI1();47}48});49robot.waitForIdle();50SwingUtilities.invokeAndWait(new Runnable() {51public void run() {52test.setupUI2();53}54});55test.test();56} finally {57if (test.frame != null) {58test.frame.dispose();59}60}61}6263private void setupUI1() {64frame = new JFrame();65frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6667left = new JPanel();68left.setPreferredSize(new Dimension(100, 100));6970JPanel rightPanel = new JPanel();71rightPanel.setPreferredSize(new Dimension(100, 50));72Component right = new JScrollPane(rightPanel);7374JSplitPane split =75new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);7677frame = new JFrame();78frame.add(split);79frame.pack();80}8182// It is important to separate frame.pack() from frame.setVisible(true).83// Otherwise the repaint manager will combine validate() calls and84// the bug won't appear.85private void setupUI2() {86frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);87frame.setLocationRelativeTo(null);88frame.setVisible(true);89}9091private void test() throws Exception {92if (left.getSize().width == 100) {93System.out.println("Test passed");94} else {95throw new RuntimeException("ScrollPaneLayout sometimes improperly " +96"calculates the preferred layout size. ");97}98}99}100101102