Path: blob/master/test/jdk/javax/swing/GroupLayout/8079640/bug8079640.java
41155 views
/*1* Copyright (c) 2015, 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 807964027* @summary GroupLayout incorrect layout with large JTextArea28* @author Semyon Sadetsky29*/303132import javax.swing.*;33import java.awt.*;3435public class bug8079640 {3637private static JFrame frame;38private static JComponent comp2;3940public static void main(String[] args) throws Exception {4142try {43SwingUtilities.invokeAndWait(new Runnable() {44@Override45public void run() {46frame = new JFrame("A Frame");47frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);48frame.setUndecorated(true);49setup(frame);50frame.setVisible(true);51}52});5354test();55System.out.println("ok");5657} finally {58SwingUtilities.invokeLater(new Runnable() {59@Override60public void run() {61frame.dispose();62}63});64}65}6667private static void test() throws Exception {68SwingUtilities.invokeAndWait(new Runnable() {69@Override70public void run() {71if(comp2.getLocation().getY() > frame.getHeight())72throw new RuntimeException("GroupLayout fails: comp2 is out of the window");73}74});75}767778static void setup(JFrame frame) {79JPanel panel = new JPanel();80JComponent comp1 = new JLabel("Test Label 1");81comp1.setMinimumSize(new Dimension(1000, 40000));82comp1.setPreferredSize(new Dimension(1000, 40000));83JScrollPane scroll = new JScrollPane(comp1);84comp2 = new JLabel("Test Label 2");85GroupLayout layout = new GroupLayout(panel);86layout.setHorizontalGroup(87layout.createParallelGroup(GroupLayout.Alignment.LEADING)88.addComponent(scroll)89.addComponent(comp2));90layout.setVerticalGroup(91layout.createSequentialGroup()92.addComponent(scroll)93.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)94.addComponent(comp2));95panel.setLayout(layout);96frame.getContentPane().add(panel, BorderLayout.CENTER);97frame.setSize(800, 600);98}99100}101102103