jdk/test/javax/swing/JTabbedPane/6670274/bug6670274.java
author duke
Wed, 05 Jul 2017 17:52:05 +0200
changeset 10620 9df40a1578ef
parent 6374 e214162c907e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5596
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     1
/*
6374
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5596
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5596
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     4
 *
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     8
 *
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    13
 * accompanied this code).
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    14
 *
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    18
 *
6374
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5596
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5596
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5596
diff changeset
    21
 * questions.
5596
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    22
 */
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    23
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    24
/*@test
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    25
  @bug 6670274
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    26
  @summary Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    27
  @author Alexander Potochkin
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    28
  @run main bug6670274
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    29
*/
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    30
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    31
import javax.swing.*;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    32
import javax.swing.plaf.basic.BasicTabbedPaneUI;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    33
import javax.swing.text.View;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    34
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    35
public class bug6670274 {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    36
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    37
    private static void createGui() {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    38
        final JTabbedPane pane = new JTabbedPane();
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    39
        TestTabbedPaneUI ui = new TestTabbedPaneUI();
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    40
        pane.setUI(ui);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    41
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    42
        pane.add("one", new JPanel());
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    43
        pane.add("<html><i>Two</i></html>", new JPanel());
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    44
        pane.add("three", new JPanel());
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    45
        pane.setTitleAt(0, "<html><i>ONE</i></html>");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    46
        check(ui, 0, 1);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    47
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    48
        pane.setTitleAt(1, "hello");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    49
        check(ui, 0);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    50
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    51
        pane.setTitleAt(0, "<html>html</html>");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    52
        pane.setTitleAt(2, "<html>html</html>");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    53
        check(ui, 0, 2);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    54
    }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    55
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    56
    private static void check(TestTabbedPaneUI ui, int... indices) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    57
        for(int i = 0; i < ui.getTabbedPane().getTabCount(); i++) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    58
            System.out.print("Checking tab #" + i);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    59
            View view = ui.getTextViewForTab(i);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    60
            boolean found = false;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    61
            for (int j = 0; j < indices.length; j++) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    62
                if (indices[j]== i) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    63
                    found = true;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    64
                    break;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    65
                }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    66
            }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    67
            System.out.print("; view = " + view);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    68
            if (found) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    69
                if (view == null) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    70
                    throw new RuntimeException("View is unexpectedly null");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    71
                }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    72
            } else if (view != null) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    73
                throw new RuntimeException("View is unexpectedly not null");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    74
            }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    75
            System.out.println(" ok");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    76
        }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    77
        System.out.println("");
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    78
    }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    79
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    80
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    81
    static class TestTabbedPaneUI extends BasicTabbedPaneUI {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    82
        public View getTextViewForTab(int tabIndex) {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    83
            return super.getTextViewForTab(tabIndex);
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    84
        }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    85
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    86
        public JTabbedPane getTabbedPane() {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    87
            return tabPane;
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    88
        }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    89
    }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    90
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    91
    public static void main(String[] args) throws Exception {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    92
        SwingUtilities.invokeAndWait(new Runnable() {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    93
            public void run() {
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    94
                bug6670274.createGui();
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    95
            }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    96
        });
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    97
    }
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents:
diff changeset
    98
}