jdk/test/javax/swing/border/Test7149090.java
author mchung
Mon, 23 Nov 2015 12:44:43 -0800
changeset 34253 ba3946143842
parent 12411 a85a15e74ad5
child 42338 a60f280f803c
permissions -rw-r--r--
8140450: Implement JEP 259: Stack-Walking API Reviewed-by: coleenp, dfuchs, bchristi, psandoz, sspitsyn Contributed-by: Mandy Chung <mandy.chung@oracle.com>, Brent Christian <brent.christian@oracle.com>, Daniel Fuchs <daniel.fuchs@oracle.com>, Hamlin Li <huaming.li@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12411
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     1
/*
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     4
 *
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     8
 *
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    13
 * accompanied this code).
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    14
 *
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    18
 *
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    21
 * questions.
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    22
 */
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    23
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    24
/* @test
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    25
   @bug 7149090
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    26
   @summary Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    28
*/
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    29
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    30
import javax.swing.*;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    31
import javax.swing.border.EmptyBorder;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    32
import javax.swing.border.TitledBorder;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    33
import java.lang.reflect.InvocationTargetException;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    34
import java.lang.reflect.Method;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    35
import java.util.ArrayList;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    36
import java.util.List;
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    37
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    38
public class Test7149090 {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    39
    private static final Object[][] DEFAULT_TITLE_POSITIONS = {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    40
            {"Metal", TitledBorder.TOP},
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    41
            {"Motif", TitledBorder.TOP},
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    42
            {"Windows", TitledBorder.TOP},
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    43
            {"Nimbus", TitledBorder.ABOVE_TOP},
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    44
    };
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    45
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    47
        for (UIManager.LookAndFeelInfo lookAndFeel : UIManager.getInstalledLookAndFeels()) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    48
            for (Object[] defaultTitlePosition : DEFAULT_TITLE_POSITIONS) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    49
                if (defaultTitlePosition[0].equals(lookAndFeel.getName())) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    50
                    UIManager.setLookAndFeel(lookAndFeel.getClassName());
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    51
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    52
                    final int expectedPosition = (Integer) defaultTitlePosition[1];
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    53
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    54
                    SwingUtilities.invokeAndWait(new Runnable() {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    55
                        @Override
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    56
                        public void run() {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    57
                            List<TitledBorder> borders = new ArrayList<>();
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    58
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    59
                            borders.add(BorderFactory.createTitledBorder(new EmptyBorder(0, 0, 0, 0), "Title"));
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    60
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    61
                            try {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    62
                                Method getPositionMethod = TitledBorder.class.getDeclaredMethod("getPosition");
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    63
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    64
                                getPositionMethod.setAccessible(true);
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    65
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    66
                                for (TitledBorder border : borders) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    67
                                    int position = (Integer) getPositionMethod.invoke(border);
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    68
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    69
                                    if (position != expectedPosition) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    70
                                        throw new RuntimeException("Invalid title position");
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    71
                                    }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    72
                                }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    73
                            } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    74
                                throw new RuntimeException(e);
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    75
                            }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    76
                        }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    77
                    });
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    78
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    79
                    System.out.println("Test passed for LookAndFeel " + lookAndFeel.getName());
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    80
                }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    81
            }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    82
        }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    83
    }
a85a15e74ad5 7149090: Nimbus:BorderFactory.createTitledBorder() the DEFAULT position of a title is not the same as the TOP
rupashka
parents:
diff changeset
    84
}