test/jdk/javax/swing/JEditorPane/8226513/JEditorPaneLayoutTest.java
author psadhukhan
Mon, 19 Aug 2019 12:13:47 +0530
changeset 57931 39f133168348
permissions -rw-r--r--
8226513: JEditorPane is shown with incorrect size Reviewed-by: prr, psadhukhan Contributed-by: semyon.sadetsky@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57931
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     1
/*
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     4
 *
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     8
 *
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    13
 * accompanied this code).
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    14
 *
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    18
 *
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    21
 * questions.
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    22
 */
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    23
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    24
/**
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    25
 * @test
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    26
 * @key headful
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    27
 * @bug 8226513
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    28
 * @summary JEditorPane is shown with incorrect size
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    29
 * @run main/othervm -Dsun.java2d.uiScale=1.0 JEditorPaneLayoutTest
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    30
 */
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    31
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    32
import javax.swing.JFrame;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    33
import javax.swing.JEditorPane;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    34
import javax.swing.SwingUtilities;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    35
import javax.swing.text.BadLocationException;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    36
import javax.swing.text.Document;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    37
import javax.swing.text.html.HTMLEditorKit;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    38
import java.awt.Dimension;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    39
import java.awt.Robot;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    40
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    41
public class JEditorPaneLayoutTest {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    42
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    43
    public static final String TEXT =
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    44
                                "some text some text some text <br> some text";
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    45
    static JFrame frame;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    46
    static JEditorPane editorPane;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    47
    static Dimension size1;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    48
    static Dimension size2;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    49
    static Dimension size3;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    50
    static Dimension size4;
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    51
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    53
        Robot robot = new Robot();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    54
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    55
        SwingUtilities.invokeAndWait(() -> {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    56
            frame = new JFrame();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    57
            editorPane = new JEditorPane("text/html", TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    58
            size1 = editorPane.getPreferredSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    59
            editorPane.setText(TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    60
            frame.add(editorPane);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    61
            frame.pack();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    62
            frame.setLocationRelativeTo(null);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    63
            frame.setVisible(true);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    64
        });
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    65
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    66
        robot.waitForIdle();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    67
        robot.delay(300);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    68
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    69
        SwingUtilities.invokeAndWait(() -> {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    70
            size2 = editorPane.getSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    71
            frame.dispose();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    72
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    73
            frame = new JFrame();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    74
            editorPane = new JEditorPane("text/html", TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    75
            editorPane.getPreferredSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    76
            editorPane.setText(TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    77
            frame.add(editorPane);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    78
            frame.setLocationRelativeTo(null);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    79
            frame.setVisible(true);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    80
        });
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    81
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    82
        robot.waitForIdle();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    83
        robot.delay(300);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    84
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    85
        if (!size1.equals(size2)) {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    86
            SwingUtilities.invokeLater(frame::dispose);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    87
            throw new RuntimeException("Wrong size " + size2 +
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    88
                    " expected " + size1);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    89
        }
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    90
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    91
        SwingUtilities.invokeAndWait(() -> {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    92
            editorPane.setText(TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    93
            frame.pack();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    94
            size3 = editorPane.getSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    95
            frame.dispose();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    96
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    97
            frame = new JFrame();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    98
            editorPane = new JEditorPane("text/html", TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
    99
            editorPane.getPreferredSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   100
            editorPane.setSize(1, 1);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   101
            Document doc = new HTMLEditorKit().createDefaultDocument();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   102
            try {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   103
                doc.insertString(0, TEXT, null);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   104
            } catch (BadLocationException e) {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   105
                e.printStackTrace();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   106
            }
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   107
            editorPane.setDocument(doc);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   108
            editorPane.setText(TEXT);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   109
            frame.add(editorPane);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   110
            frame.pack();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   111
            frame.setLocationRelativeTo(null);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   112
            frame.setVisible(true);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   113
        });
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   114
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   115
        robot.waitForIdle();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   116
        robot.delay(300);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   117
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   118
        if (!size1.equals(size3)) {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   119
            SwingUtilities.invokeLater(frame::dispose);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   120
            throw new RuntimeException("Wrong size " + size3 +
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   121
                    " expected " + size1);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   122
        }
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   123
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   124
        SwingUtilities.invokeAndWait(() -> {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   125
            size4 = editorPane.getSize();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   126
            frame.dispose();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   127
        });
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   128
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   129
        robot.waitForIdle();
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   130
        robot.delay(300);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   131
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   132
        if (!size1.equals(size4)) {
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   133
            SwingUtilities.invokeLater(frame::dispose);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   134
            throw new RuntimeException("Wrong size " + size4 +
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   135
                    " expected " + size1);
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   136
        }
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   137
    }
39f133168348 8226513: JEditorPane is shown with incorrect size
psadhukhan
parents:
diff changeset
   138
}