JDK-6670274 : Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2008-03-03
  • Updated: 2016-07-11
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u18Fixed 7 b97Fixed
Related Reports
Relates :  
Relates :  
Relates :  
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 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
22-05-2009

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

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.
03-04-2008

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(); } }); } }
14-03-2008