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

JTabbedPane can fail to display selected component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.2.0, 1.2.2, 1.4.0
    • client-libs
    • hopper
    • x86
    • windows_nt, windows_2000

      The following code creates a tabbed pane with one tab. When the button at the bottom of the frame is clicked it invokes removeAll on the JTabbedPane followed by a addTab to add the component back to the JTabbedPane. When the button is clicked the component in the tab is no longer visible (isVisible == false).

      I believe this is happening because BasicTabbedPaneUI caches the visibleComponent, and does not check if the component has become not visible.

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

      public class TabTest {
          public static void main(String[] args) {
              JFrame frame = new JFrame("Tab test");
              final JTabbedPane tp = new JTabbedPane();
              final JLabel testLabel = new JLabel("TEST");

              tp.addTab("Test", testLabel);
              frame.getContentPane().add(tp);
              frame.setDefaultCloseOperation(3);

              // Widgets to add/remove testLabel
              JButton button = new JButton("Test");
              button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                      tp.removeAll();
                      tp.addTab("Test", testLabel);
                      System.out.println("Is visible: " + testLabel.isVisible());
                      if (!testLabel.isVisible()) {
                          testLabel.setVisible(true);
                      }
                  }
              });
              frame.getContentPane().add(button, BorderLayout.SOUTH);
              frame.pack();
              frame.show();
          }
      }


      Name: rlT66838 Date: 12/06/99


      jdk 1.2.2 classic or hotspot

      I guess that the problem with jtabbedpane I had may be the same as
      bug 4190719.

      I add four components to a jtabbedpane. After making it visible, I
      select the first tab and the contents belong to the third. After I select
      third tab and then select the first again,the component is updated
      to the right one.

      If you need the codes, I will email you the jar file.

      Thanks,

      Yuhong Wang

      ###@###.###
      (Review ID: 98692)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: