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