1 /*
   2  * Copyright (c) 2015, 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 /* @test
  25    @bug 8079640
  26    @summary GroupLayout incorrect layout with large JTextArea
  27    @author Semyon Sadetsky
  28   */
  29 
  30 
  31 import javax.swing.*;
  32 import java.awt.*;
  33 
  34 public class bug8079640 {
  35 
  36     private static JFrame frame;
  37     private static JComponent comp2;
  38 
  39     public static void main(String[] args) throws Exception {
  40 
  41         try {
  42             SwingUtilities.invokeAndWait(new Runnable() {
  43                 @Override
  44                 public void run() {
  45                     frame = new JFrame("A Frame");
  46                     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47                     frame.setUndecorated(true);
  48                     setup(frame);
  49                     frame.setVisible(true);
  50                 }
  51             });
  52 
  53             test();
  54             System.out.println("ok");
  55 
  56         } finally {
  57             SwingUtilities.invokeLater(new Runnable() {
  58                 @Override
  59                 public void run() {
  60                     frame.dispose();
  61                 }
  62             });
  63         }
  64     }
  65 
  66     private static void test() throws Exception {
  67         SwingUtilities.invokeAndWait(new Runnable() {
  68             @Override
  69             public void run() {
  70                 if(comp2.getLocation().getY() > frame.getHeight())
  71                     throw new RuntimeException("GroupLayout fails: comp2 is out of the window");
  72             }
  73         });
  74     }
  75 
  76 
  77     static void setup(JFrame frame)  {
  78         JPanel panel = new JPanel();
  79         JComponent comp1 = new JLabel("Test Label 1");
  80         comp1.setMinimumSize(new Dimension(1000, 40000));
  81         comp1.setPreferredSize(new Dimension(1000, 40000));
  82         JScrollPane scroll = new JScrollPane(comp1);
  83         comp2 = new JLabel("Test Label 2");
  84         GroupLayout layout = new GroupLayout(panel);
  85         layout.setHorizontalGroup(
  86                 layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  87                         .addComponent(scroll)
  88                         .addComponent(comp2));
  89         layout.setVerticalGroup(
  90                 layout.createSequentialGroup()
  91                         .addComponent(scroll)
  92                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  93                         .addComponent(comp2));
  94         panel.setLayout(layout);
  95         frame.getContentPane().add(panel, BorderLayout.CENTER);
  96         frame.setSize(800, 600);
  97     }
  98 
  99 }