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

REGRESSION: JTabbedPane with zero tabs and SCROLL_TAB_LAYOUT throwing exception

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b38)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b38, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP2

      A DESCRIPTION OF THE PROBLEM :
      JTabbedPane with no tabs and SCROLL_TAB_LAYOUT is not possible to render due to change in BasicTabbedPaneUI$TabbedPaneScrollLayout.layoutContainer method. It was working correctly in JDK 5.0. New code is checking for positioning of last tab, without checking if there is any tab at all.

      While probably having JTabbedPane with zero tabs doesn't make sense, in my application, I was displaying it so and then created tabs dynamically.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create new JTabbedPane(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT); and add it to some window without adding any tabs to it first, then display this window. See attached source code for short example.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With JDK 5.0, I can see expected result - frame with empty tab pane inside.
      ACTUAL -
      Exception is thrown (see stack trace below)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception occurred during event dispatching:
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
              at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneScrollLayout.layoutContainer(BasicTabbedPaneUI.java:2995)
              at java.awt.Container.layout(Container.java:1402)
              at java.awt.Container.doLayout(Container.java:1391)
              at java.awt.Container.validateTree(Container.java:1474)
              at java.awt.Container.validateTree(Container.java:1481)
              at java.awt.Container.validateTree(Container.java:1481)
              at java.awt.Container.validateTree(Container.java:1481)
              at java.awt.Container.validateTree(Container.java:1481)
              at java.awt.Container.validate(Container.java:1449)
              at java.awt.Window.dispatchEventImpl(Window.java:2010)
              at java.awt.Component.dispatchEvent(Component.java:4194)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:592)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:270)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:198)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:171)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:166)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:158)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:119)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      public class TabTest {
        public static void main(String[] argv) {
          JFrame jf = new JFrame("Tab test");
          JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT);
          jf.add(pane);
          jf.setSize(100,100);
          jf.setVisible(true);
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Make JTabbedPane not visible and show it only after adding first tab. Same, add a logic to hide it if you have deleted last tab.

      Release Regression From : 5.0
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-06-02 10:31:05 GMT

            alexp Alexander Potochkin (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: