Path: blob/master/test/jdk/javax/swing/JScrollPane/6274267/bug6274267.java
41153 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/*26* @test27* @key headful28* @bug 627426729* @summary Checks that ScrollPaneLayout properly calculates preferred30* layout size.31* @author Mikhail Lapshin32* @run main bug627426733*/3435import javax.swing.*;36import java.awt.*;3738public class bug6274267 {39private JFrame frame;40private Component left;4142public static void main(String[] args) throws Exception {43final bug6274267 test = new bug6274267();44Robot robot = new Robot();45try {46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48test.setupUI1();49}50});51robot.waitForIdle();52SwingUtilities.invokeAndWait(new Runnable() {53public void run() {54test.setupUI2();55}56});57test.test();58} finally {59if (test.frame != null) {60test.frame.dispose();61}62}63}6465private void setupUI1() {66frame = new JFrame();67frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6869left = new JPanel();70left.setPreferredSize(new Dimension(100, 100));7172JPanel rightPanel = new JPanel();73rightPanel.setPreferredSize(new Dimension(100, 50));74Component right = new JScrollPane(rightPanel);7576JSplitPane split =77new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);7879frame = new JFrame();80frame.add(split);81frame.pack();82}8384// It is important to separate frame.pack() from frame.setVisible(true).85// Otherwise the repaint manager will combine validate() calls and86// the bug won't appear.87private void setupUI2() {88frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);89frame.setLocationRelativeTo(null);90frame.setVisible(true);91}9293private void test() throws Exception {94if (left.getSize().width == 100) {95System.out.println("Test passed");96} else {97throw new RuntimeException("ScrollPaneLayout sometimes improperly " +98"calculates the preferred layout size. ");99}100}101}102103104