jdk/test/javax/swing/JLayer/6824395/bug6824395.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3737 83fb4621a129
child 27764 4e79ff3e0602
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3737
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     4
 *
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     8
 *
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    13
 * accompanied this code).
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    14
 *
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3737
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3737
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3737
diff changeset
    21
 * questions.
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    22
 */
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    23
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    24
 /*
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    25
 * @test
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    26
 * @summary Checks that JLayer inside JViewport works is correctly laid out
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    27
 * @author Alexander Potochkin
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    28
 * @run main bug6824395
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    29
 */
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    30
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    31
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    32
import sun.awt.SunToolkit;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    33
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    34
import javax.swing.*;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    35
import javax.swing.plaf.LayerUI;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    36
import java.awt.*;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    37
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    38
public class bug6824395 {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    39
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    40
    static JScrollPane scrollPane;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    41
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    43
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    44
        SwingUtilities.invokeAndWait(new Runnable() {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    45
            public void run() {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    46
                JFrame frame = new JFrame("testing");
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    47
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    48
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    49
                JEditorPane editorPane = new JEditorPane();
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    50
                String str = "hello\n";
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    51
                for(int i = 0; i<5; i++) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    52
                    str += str;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    53
                }
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    54
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    55
                editorPane.setText(str);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    56
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    57
                JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    58
                LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    59
                editorPaneLayer.setUI(layerUI);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    60
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    61
                scrollPane = new JScrollPane(editorPaneLayer);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    62
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    63
                scrollPane.setPreferredSize(new Dimension(200, 250));
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    64
                frame.add(scrollPane);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    65
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    66
                frame.setSize(200, 200);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    67
                frame.pack();
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    68
                frame.setVisible(true);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    69
            }
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    70
        });
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    71
        toolkit.realSync();
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    72
        SwingUtilities.invokeAndWait(new Runnable() {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    73
            public void run() {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    74
                if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    75
                    throw new RuntimeException("Wrong component's width!");
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    76
                }
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    77
            }
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    78
        });
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    79
    }
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents:
diff changeset
    80
}