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

JTabbedPane does not revalidate following removal and readdition of tabs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs



      Name: jk109818 Date: 01/08/2002


      FULL PRODUCT VERSION :
      C:\java\dev>java -version
      java version "1.3.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
      Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

      FULL OPERATING SYSTEM VERSION : Windows NT Version 4.0




      A DESCRIPTION OF THE PROBLEM :
      When a shown JTabbedPane's tabs are removed, readded, and
      revalidated, the initially shown tab/panel is not layed out
      and appears as blank.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Build a JTabbedPane with multiple tabs. Show it. Make sure
      the 0th tab is selected. Remove all of the tabs. Re-add all
      of the tabs. The shown tab will appear as blank and unlayed
      out / empty. You have to click off of and then back onto
      the initial tab to get the 0th tab to show layed out at all.

      Side Note: If you click off of the 0th tab before removing
      the panels, when you add the tabs back the 0th tab will be
      selected and shown correctly.

      Run the attached test code and click the Rebuild button.
      The initially shown content, "Content TestPanel #0"
      disappears, until you select a different tab, and then
      reselect the "TestPanel #0" tab.

      Side Note: If you select one of the other tabs before
      clicking the Rebuild button the performance is correct.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      When ever tabs are added to a JTabbedPane, I expect some
      combination of (re)validate(Tree) and repaint to layout and
      show the first tab added.

      This bug can be reproduced always.

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

      public class TabbedTest extends JFrame {

      TabbedTest() {
      getContentPane().add( mainPanel );
      JButton rebuild = new JButton( "Rebuild" );
      rebuild.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent ae ) {
      rebuildTabbedPane();
      }
      } );
      mainPanel.add( rebuild, BorderLayout.NORTH );
      mainPanel.add( mainTabbedPane, BorderLayout.CENTER );
      rebuildTabbedPane();
      }

      JPanel mainPanel = new JPanel( new BorderLayout() );

      JTabbedPane mainTabbedPane = new JTabbedPane();

      JPanel testPanels[] = null;
      JPanel[] getTestPanels() {
      if( testPanels == null ) {
      testPanels = new JPanel[5];
      for( int i = 0 ; i < 5; i++ ) {
      JPanel testPanel = new JPanel();
      testPanel.add( new JLabel( "Content TestPanel
      #" + i ) );
      testPanels[i] = testPanel;
      }
      }
      return testPanels;
      }

      void rebuildTabbedPane() {
      mainTabbedPane.removeAll();

      for( int i = 0; i < 5; i++ )
      mainTabbedPane.add( getTestPanels()[i], "TestPanel #" +
      i );

      mainTabbedPane.validate();
      }

      public static void main( String args[] ) {
      TabbedTest tt = new TabbedTest();
      tt.pack();
      tt.show();
      }
      }

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

      CUSTOMER WORKAROUND :
      I tried simulating the click off of and back onto the 0th
      tab both prior to removing all of the tabs and after adding
      all of the tabs without success. I tried bombarding my code
      with calls to any of validate, revalidate, validateTree,
      and repaint without success.
      (Review ID: 138060)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: