JDK-7026933 : Large JTabbedPane tab titles are truncated in an unpleasant way
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-03-11
  • Updated: 2011-03-14
  • Resolved: 2011-03-14
Related Reports
Duplicate :  
Description
SYNOPSIS
--------
Large JTabbedPane tab titles are truncated in an unpleasant way

OPERATING SYSTEMS
-----------------
All

FULL JDK VERSION
----------------
All 1.4.2, 5.0, 6 and 7 (tested against 7-b132)

DESCRIPTION
-----------
When the title of a JTabbedPane tab is too long to fit into the tab, it is truncated in an unpleasant way and overflows the border of the tab. It would be much better to gracefully truncate the title using an ellipsis ("..."), within the border of the tab, as is the case for JLabels.

This problem only occurs when using the default WRAP_TAB_LAYOUT - the titles are truncated gracefully within the border of the tab with ellipses if the layout is changed to SCROLL_TAB_LAYOUT, so the two layouts are inconsistent.

REPRODUCTION INSTRUCTIONS
-------------------------
Compile and run the testcase provided below. Note the unpleasant way in which the titles are truncated. Try resizing the window to observe more layout unpleasantness in the underlying tabs (particularly the top tab).

TESTCASE SOURCE
---------------
import javax.swing.*;
import java.awt.*;

public class JTabbedPaneTest extends JFrame {
    public static void main(String[] args){
        JTabbedPaneTest frame = new JTabbedPaneTest();
        frame.setPreferredSize(new Dimension(300,400));
        frame.pack();
        frame.setVisible(true);
    }

    JTabbedPaneTest(){
        Container c = getContentPane();
        c.setLayout(new GridLayout(1,2));

        JTabbedPane tab = new JTabbedPane();
        String a2z = "abcdefghijklmnopqrstuvwxyz";
        tab.addTab("0" + a2z + a2z, new JLabel(a2z));
        tab.addTab("1" + a2z, new JLabel(a2z));
        tab.addTab("2" + a2z, new JLabel(a2z));
        tab.addTab("3" + a2z +a2z, new JLabel(a2z));
        //tab.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        c.add(tab);

        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());
        p.add(new JLabel("Extra panel to make problem more visible"), BorderLayout.CENTER);
        c.add(p);
    }
}

WORKAROUND:
-----------
Use SCROLL_TAB_LAYOUT.