United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6670274 Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
JDK-6670274 : Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)

Details
Type:
Bug
Submit Date:
2008-03-03
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows_vista,windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10,7
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b24)
Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6000]

A DESCRIPTION OF THE PROBLEM :
Tab titles are not shown correctly if HTML titles are used. There is problem in BasicTabbedPaneUI$Handler.updateHtmlViews() - there is htmlViews.insertElementAt(v, index); instead of htmlViews.setElementAt(v, index); so new view is added (to already preallocated vector) - this shifts/breaks others.



REPRODUCIBILITY :
This bug can be reproduced always.
bug reported to NB IDE has 5 duplicates and 4 votes already
http://www.netbeans.org/issues/show_bug.cgi?id=113388

                                    

Comments
EVALUATION

I created the following test to check the html in tabbedPane
and it works well in JDK 7

asked the submitter for more information 


import javax.swing.*;

public class bug6670274 {

    private static void createGui() {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTabbedPane pane = new JTabbedPane();
        pane.add("one", new JPanel());
        pane.add("<html><i>Two</i></html>", new JPanel());
        pane.add("three", new JPanel());

        frame.add(pane);

        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                bug6670274.createGui();
            }
        });
    }
}
                                     
2008-03-14
EVALUATION

Hi Alex,

to see the problem in your example, just add e.g.:
pane.setTitleAt(0, "<html><b>ONE</b></html>");
So, your createGui() will look:

    private static void createGui() {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTabbedPane pane = new JTabbedPane();
        pane.add("one", new JPanel());
        pane.add("<html><i>Two</i></html>", new JPanel());
        pane.add("three", new JPanel());
        pane.setTitleAt(0, "<html><b>ONE</b></html>");

        frame.add(pane);

        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

The problem is also quite obvious from source code in BasicTabbedPaneUI.Handler.updateHtmlViews() where should be enough to replace
htmlViews.insertElementAt(v, index);
by
htmlViews.setElementAt(v, index);
to fix the problem.
                                     
2008-04-03
EVALUATION

I reproduced the bug, accepted
Thanks!
                                     
2008-04-10
EVALUATION

Actually the fix is not as straighforward as it is mention in description,
we should use htmlView.insertElementAt() when the tab is added
and shouldn't insert the new element if the tab's title is updated

when the component is removed BasicTabbedPaneUI 
directly removes the element from htmlViews, see Handler.componentRemoved().

So the simplest fix is to do the same when the title is updated,
the new correct element will be inserted by the updateHtmlViews(index) after that
                                     
2009-05-22



Hardware and Software, Engineered to Work Together