Path: blob/master/test/jdk/javax/swing/GroupLayout/8013566/bug8013566.java
41153 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 801356627* @summary Failure of GroupLayout in combination of addPreferredGap and addGroup's28* last row29* @author Semyon Sadetsky30*/3132import javax.swing.*;3334public class bug8013566 {3536public static void main(String[] args) throws Exception {37SwingUtilities.invokeAndWait(new Runnable() {38public void run() {39final JFrame frame = new JFrame();40try {41frame.setUndecorated(true);42frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);43test(frame);444546} finally {47frame.dispose();48}49}50});5152System.out.println("ok");53}5455static void test(JFrame frame) {56JComponent c1 = new JButton("Label1");57JComponent c2 = new JButton("Label22");58JComponent c3 = new JButton("Label333");5960JPanel panel = new JPanel();61GroupLayout layout = new GroupLayout(panel);62layout.setAutoCreateContainerGaps(true);63layout.setAutoCreateGaps(true);64panel.setLayout(layout);6566layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(67layout.createParallelGroup().addGroup(68layout.createSequentialGroup().addComponent(c1)69.addPreferredGap(70LayoutStyle.ComponentPlacement.RELATED,7150, 200))72.addComponent(c2)).addComponent(c3));7374layout.setVerticalGroup(layout.createSequentialGroup()75.addComponent(c1).addComponent(c2).addComponent(c3)76);7778frame.setContentPane(panel);79frame.pack();80frame.setVisible(true);8182if (c3.getX() != c1.getX() + c1.getWidth() + 50) {83throw new RuntimeException(84"Gap between 1st and 3rd component is wrong");85}8687}88}899091