Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7151452

JTabbedPane preferred size calculation is wrong for SCROLL_TAB_LAYOUT

XMLWordPrintable

      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)

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: