jdk/test/javax/swing/GroupLayout/8013566/bug8013566.java
author vromero
Thu, 05 Jan 2017 11:16:39 -0800
changeset 43033 c37b643739a7
parent 40128 e635645d2a8a
permissions -rw-r--r--
8148100: Convert lambda most specific positive tests to check runtime behavior Reviewed-by: mcimadamore Contributed-by: bsrbnd@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29895
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     1
/*
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     4
 *
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     8
 *
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    13
 * accompanied this code).
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    14
 *
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    18
 *
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    21
 * questions.
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    22
 */
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    23
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    24
/*
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    25
 * @test
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    26
 * @key headful
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    27
 * @bug 8013566
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    28
 * @summary Failure of GroupLayout in combination of addPreferredGap and addGroup's
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    29
 * last row
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    30
 * @author Semyon Sadetsky
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 29895
diff changeset
    31
 */
29895
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    32
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    33
import javax.swing.*;
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    34
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    35
public class bug8013566 {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    36
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    38
        SwingUtilities.invokeAndWait(new Runnable() {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    39
            public void run() {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    40
                final JFrame frame = new JFrame();
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    41
                try {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    42
                    frame.setUndecorated(true);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    43
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    44
                    test(frame);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    45
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    46
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    47
                } finally {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    48
                    frame.dispose();
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    49
                }
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    50
            }
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    51
        });
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    52
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    53
        System.out.println("ok");
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    54
    }
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    55
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    56
    static void test(JFrame frame) {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    57
        JComponent c1 = new JButton("Label1");
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    58
        JComponent c2 = new JButton("Label22");
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    59
        JComponent c3 = new JButton("Label333");
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    60
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    61
        JPanel panel = new JPanel();
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    62
        GroupLayout layout = new GroupLayout(panel);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    63
        layout.setAutoCreateContainerGaps(true);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    64
        layout.setAutoCreateGaps(true);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    65
        panel.setLayout(layout);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    66
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    67
        layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    68
                layout.createParallelGroup().addGroup(
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    69
                        layout.createSequentialGroup().addComponent(c1)
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    70
                                .addPreferredGap(
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    71
                                        LayoutStyle.ComponentPlacement.RELATED,
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    72
                                        50, 200))
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    73
                        .addComponent(c2)).addComponent(c3));
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    74
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    75
        layout.setVerticalGroup(layout.createSequentialGroup()
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    76
                        .addComponent(c1).addComponent(c2).addComponent(c3)
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    77
        );
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    78
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    79
        frame.setContentPane(panel);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    80
        frame.pack();
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    81
        frame.setVisible(true);
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    82
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    83
        if (c3.getX() != c1.getX() + c1.getWidth() + 50) {
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    84
            throw new RuntimeException(
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    85
                    "Gap between 1st and 3rd component is wrong");
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    86
        }
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    87
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    88
    }
3c33719ebc18 8013566: Failure of GroupLayout in combination of addPreferredGap and addGroup'srow
ssadetsky
parents:
diff changeset
    89
}