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

heaveyweight components inside invisible lightweight containers still show

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.1.5, 1.1.8_003, 1.3.0, 6
    • client-libs
    • b08
    • generic, x86, sparc
    • generic, solaris_2.6, windows_95, windows_nt
    • Verified

      Name: rk38400 Date: 05/20/98


      //TabbedPanelAppl

      import java.awt.*;
      import com.sun.java.swing.event.*;
      import com.sun.java.swing.*;


        /**A tabbed panel with an identifing label on each pane*/
      class TabbedPanel extends JPanel {
          //The tab labels
        String tabnames[] = {"One", "Two", "Three", "Four"};
          //The tabbed pane
        public JTabbedPane tabbedPane = new JTabbedPane();

        public TabbedPanel() {
          super();
            // set layout and color
          setLayout (new BorderLayout());
          tabbedPane.setBackground(Color.red);
            // add the tabbed panes with tab labels and label in pane
          for (int i=0;i<tabnames.length;i++)
            tabbedPane.addTab (tabnames[i], null,
                      createPane (tabnames[i], (i % 2) == 0 ),
                                            "help" + i);
          tabbedPane.setSelectedIndex(0);
          add (tabbedPane, BorderLayout.CENTER);
       // reshape(10,10,300,200);
          }
              
          //Create a pane with background color
        JPanel createPane(String s, boolean useTextArea) {
          JPanel p = new JPanel();
          
          p.setBackground (Color.yellow);
          p.add(new JLabel(s));
          
            //add a text area or a text field
          if (useTextArea) {
            TextArea theAreaData = new TextArea(3,20);
            String alltext = new String();
            for (int i = 0; i < 10; i++) alltext = alltext + s + "\n";
            theAreaData.setText(alltext);
            theAreaData.setBackground(Color.white);
            p.add(theAreaData);
          } else {
            TextField theFieldData = new TextField(s);
            theFieldData.setBackground(Color.white);
            p.add(theFieldData);
          }
          return p;
        }
          /**provides the preferred size */
        public Dimension getPreferredSize() {return new Dimension(200,200);}

      }
            
      public class TabbedPanelAppl extends Frame {
      TabbedPanel aTabbedPanel;

        public TabbedPanelAppl() {
          reshape(10,10,300,200);
      // create the tabbed panel, add to applet, remember selection
      aTabbedPanel = new TabbedPanel();
      add(aTabbedPanel);
      }
          
        public static void main(String [] argv) {
          TabbedPanelAppl thetest = new TabbedPanelAppl();
          thetest.show();
        }

      }
      (Review ID: 30643)
      ======================================================================

      Name: dbT83986 Date: 05/14/99


      When JTabbedPane contains JPanel with awt components
      (Label or TextField) all components from all tabs
      (also hidden at the moment) are shown after creation.
      The following code shows it:

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

      public class Test extends JDialog{
      public Test(){
      super();
      JTabbedPane tab=new JTabbedPane();

      Container p=new JPanel();
      Component c1=new Label("AAAAAAAA");
      p.add(c1);
      tab.add(p,"l1");

      p=new JPanel();
      Component c2=new TextField(5);
      p.add(c2);
      tab.add(p,"l2");

      getContentPane().add(tab);
      pack();
      setVisible(true);
      }

      static void main(String[]args){
      Container f=new Test();
      }
      }

      This code should show JTabbedPane with two tabs: first with Label and the second with TextField, but both components are mistakely visible.
      This example works OK when using Panel instead of JPanel or when using JTextField and JLabel instead of TextField and Label.
      I observed this bug in JDK 1.2 and JDK 1.1.8 with swing 1.1 or 1.1.1 beta2
      (Review ID: 63186)
      ======================================================================

            art Artem Ananiev (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: