Path: blob/master/test/jdk/javax/swing/JTabbedPane/6670274/bug6670274.java
41153 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*@test24@bug 667027425@summary Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)26@author Alexander Potochkin27@run main bug667027428*/2930import javax.swing.*;31import javax.swing.plaf.basic.BasicTabbedPaneUI;32import javax.swing.text.View;3334public class bug6670274 {3536private static void createGui() {37final JTabbedPane pane = new JTabbedPane();38TestTabbedPaneUI ui = new TestTabbedPaneUI();39pane.setUI(ui);4041pane.add("one", new JPanel());42pane.add("<html><i>Two</i></html>", new JPanel());43pane.add("three", new JPanel());44pane.setTitleAt(0, "<html><i>ONE</i></html>");45check(ui, 0, 1);4647pane.setTitleAt(1, "hello");48check(ui, 0);4950pane.setTitleAt(0, "<html>html</html>");51pane.setTitleAt(2, "<html>html</html>");52check(ui, 0, 2);53}5455private static void check(TestTabbedPaneUI ui, int... indices) {56for(int i = 0; i < ui.getTabbedPane().getTabCount(); i++) {57System.out.print("Checking tab #" + i);58View view = ui.getTextViewForTab(i);59boolean found = false;60for (int j = 0; j < indices.length; j++) {61if (indices[j]== i) {62found = true;63break;64}65}66System.out.print("; view = " + view);67if (found) {68if (view == null) {69throw new RuntimeException("View is unexpectedly null");70}71} else if (view != null) {72throw new RuntimeException("View is unexpectedly not null");73}74System.out.println(" ok");75}76System.out.println("");77}787980static class TestTabbedPaneUI extends BasicTabbedPaneUI {81public View getTextViewForTab(int tabIndex) {82return super.getTextViewForTab(tabIndex);83}8485public JTabbedPane getTabbedPane() {86return tabPane;87}88}8990public static void main(String[] args) throws Exception {91SwingUtilities.invokeAndWait(new Runnable() {92public void run() {93bug6670274.createGui();94}95});96}97}9899100