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

JTabbedPane spec has incomplete info about add(Component) method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0
    • docs
    • beta
    • generic
    • generic


      The JTabbedPane specs says the following about the add(Component) method:
        public Component add(Component component)
          Adds a component with a tab title defaulting to the name of the component.

      The spec does not clarify what the "name" of a component means.
      As the following application shows, the tab of a JTextarea that is added to
      a tabbed pane has no title. The same is true if a JButton with a non-empty
      title is added to the tabbed pane.

      =============================================================================
      /*
       * JTabbedPaneTest.java
       * JTabbedPane spec has incomplete info about add(Component) method
      */


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

      public class JTabbedPaneTest extends JFrame implements ActionListener {
          JTabbedPane tabbedPane;
          JButton add;
          JPanel infoPanel = new JPanel();
          JPanel p1 = new JPanel();
          JPanel p2 = new JPanel();
          JPanel panel1 = new JPanel();
          JPanel panel2 = new JPanel();
          JPanel panel3 = new JPanel();
          JPanel panel4 = new JPanel();

          public JTabbedPaneTest() {
              Container c = getContentPane();
      c.setLayout(new BorderLayout());

      infoPanel.setLayout(new GridLayout(0,1));
              infoPanel.add(new JLabel("JTabbedPane spec has incomplete info about add(Component) method."));
              infoPanel.add(new JLabel("It does not clarify what \"name\" of a component means."));
              infoPanel.add(new JLabel(""));
              infoPanel.setBackground(Color.white);
              c.add(BorderLayout.NORTH, infoPanel);

              tabbedPane = new JTabbedPane();
              panel1.setBackground(Color.red);
              panel2.setBackground(Color.blue);
              panel3.setBackground(Color.green);
              panel4.setBackground(Color.yellow);
              tabbedPane.addTab("Red", panel1);
              tabbedPane.addTab("Blue", panel2);
              tabbedPane.addTab("Green", panel3);
              tabbedPane.addTab("Yellow", panel4);

              add = new JButton("Add component");
              add.setBackground(new Color(170,150,250));
              add.setToolTipText("Invokes JTabbedPane.add().");
              add.addActionListener(this);

              p1.setLayout(new BorderLayout());
      p1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
              p1.add(BorderLayout.CENTER, tabbedPane);
              c.add(BorderLayout.CENTER, p1);

              p2.add(add);
              p2.setBackground(Color.pink);
              c.add(BorderLayout.SOUTH, p2);
          }

          public static void main(String argv[]) {
              JFrame frame = new JTabbedPaneTest();
      frame.setTitle("JTabbedPane.add() Test");
      frame.pack();
      frame.setSize(725,400);
      frame.setVisible(true);
          }

          public void actionPerformed(ActionEvent e) {
      Object source = e.getSource();

      if (source == add) {
      tabbedPane.add(new JTextArea("A Textarea"));
      }
          }
      }
      =============================================================================

            sharonz Sharon Zakhour (Inactive)
            gaurisha Gauri Sharma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: