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

JTabbedPane's tabs disappear with large tab height and a 2nd column is needed

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b95)


      A DESCRIPTION OF THE PROBLEM :
      When the tab of a JTabbedPane has a large height value and its placed on the Right or Left side the tabs will become hidden when more than one tab run is needed. This I believe is because the code in MetalTabbedPaneUI.getTabRunOverlay is returning a larger than "normal" value. Usually tab text is layed out horizontally, but if the text is embeded in html it can become vertical.

      Code in question:
          protected int getTabRunOverlay( int tabPlacement ) {
              // Tab runs laid out vertically should overlap
              // at least as much as the largest slant
              if ( tabPlacement == LEFT || tabPlacement == RIGHT ) {
                  int maxTabHeight = calculateMaxTabHeight(tabPlacement);
                  return maxTabHeight / 2;
              }
              return 0;
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run this test code
      2) Add tabs until they go away. Remove the tabs until they reappear.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      that a 2nd or Nth column appears
      ACTUAL -
      columns are hidden

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;


      public class JTabbedPaneBug implements Runnable{

          String title = "<html><pre>A\nl\no\nn\ng\nt\nt\ni\nt\nl\ne\n</pre></html>";
          public void run(){
              create(JTabbedPane.LEFT, 0, 0);
              create(JTabbedPane.RIGHT, 501, 0);
          }

          public void create(int placement, int x, int y){
              final JTabbedPane jtp = new JTabbedPane();
              jtp.setTabPlacement(placement);
              for(int i = 0; i < 2; i ++)
                  jtp.add(title, new JLabel(String.valueOf(i)));
              JFrame jf = new JFrame();
              jf.add(jtp);
              JButton jb = new JButton("Add");
              jb.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
                          jtp.add(title, new JLabel("New!"));
                      }
      });
              JButton jb2 = new JButton("Remove");
              jb2.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
                          int count = jtp.getTabCount();
                          if(count != 0){
                              jtp.removeTabAt(0);
                          }
                      }
      });
              JPanel jp = new JPanel();
              jp.add(jb); jp.add(jb2);
              jf.add(jp, BorderLayout.SOUTH);
              jf.setSize(500,500);
              jf.setLocation(x, y);
              jf.setVisible(true);
          }


          public static void main(String ... args){
      SwingUtilities.invokeLater(new JTabbedPaneBug());
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      subclass MetalTabbedPaneUI and return a different value from getTabRunOverlay

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: