JDK-7151452 : JTabbedPane preferred size calculation is wrong for SCROLL_TAB_LAYOUT
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2012-03-06
  • Updated: 2019-03-06
  • Resolved: 2019-03-06
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.
Other
tbdResolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Windows 6.0.6002

A DESCRIPTION OF THE PROBLEM :
Preferred size calculation is incorrect for JTabbedPane if SCROLL_TAB_LAYOUT is used. Content will always get less than preferred size.  For tab placement TOP/BOTTOM height is to small, for LEFT/RIGHT width is too small

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run example provided and compare the two frames. For SCROLL_TAB_LAYOUT the border of the content is not fully shown

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both tab layout policies should behave the same regarding content sizing
ACTUAL -
For SCROLL_TAB_LAYOUT the content is not fully shown

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package tabprob;

import java.awt.*;
import javax.swing.*;

public class TabProb extends JFrame {
  class FixLayout implements LayoutManager {
    @Override
    public void layoutContainer(Container C) {
      Insets in = C.getInsets();
      int w = 200 - in.left - in.right;
      int h = 100 - in.top - in.bottom;
      C.getComponents()[0].setBounds(in.top, in.left, w, h);
    }
    @Override
    public Dimension minimumLayoutSize(Container C) {
      return new Dimension(200, 100);
    }
    @Override
    public Dimension preferredLayoutSize(Container C) {
      return new Dimension(200, 100);
    }
    @Override
    public void removeLayoutComponent(Component c) {
    }
    @Override
    public void addLayoutComponent(String s, Component c) {
    }
  }

  public TabProb(int layoutPolicy) {
    JTabbedPane tabpanel = new JTabbedPane();
    tabpanel.setTabPlacement(JTabbedPane.TOP);
    tabpanel.setTabLayoutPolicy(layoutPolicy);
    JPanel panel = new JPanel(new FixLayout());
    JLabel label = new JLabel("TEST");
    label.setBorder(BorderFactory.createLineBorder(Color.green, 3));
    panel.add(label);
    tabpanel.add("TEST", panel);
    add(tabpanel, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  }

  public static void main(String[] args) {
    try {
      //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
      //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch(Exception e) {
    }
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        TabProb tb1 = new TabProb(JTabbedPane.SCROLL_TAB_LAYOUT);
        tb1.pack();
        tb1.setVisible(true);
        
        TabProb tb2 = new TabProb(JTabbedPane.WRAP_TAB_LAYOUT);
        tb2.pack();
        tb2.setVisible(true);
      }
    });
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
1) Set a large enough inset for the contentpanel, or
2) Set TabbedPane.tabAreaInsets to Insets(0,0,0,0)

Comments
- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

EVALUATION the workaround exists
19-03-2012