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

If JTabbedPane's components are smaller than tabs, preferred size is not correct

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2
    • client-libs
    • beta
    • x86
    • windows_nt



      Name: et89391 Date: 08/13/99


      java version:
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      In a JTabbedPane for which the placement is BOTTOM,
      if the tabs are associated to empty components (of size 0),
      the height of the pane is incorrect:
      when all the tabs fit on a row, the height of the panel should be equal
      (approximatively) to the height of a tab.
      In JDK 1.2.2 it is equal to the height of a tab multiplied by the number of tabs.

      Note that the problem also occures if the components have a preferred width
      smaller than the width of the tabs.

      Note that in JDK 1.2.1 this worked fined if there was only one row.
      But the height was wrong when there was several rows.

      Use the following code to reproduce the problem.
      Use the buttons to add and remove tabs and see how the JTabbedPane displays.

      import javax.swing.*;
      import javax.swing.event.*;
      import java.awt.*;
      import java.awt.event.*;
      public class TabbedPaneTest extends JPanel implements ActionListener
      {
          JDesktopPane desktop = new JDesktopPane();
          JTabbedPane tabs = new JTabbedPane(SwingConstants.BOTTOM);
          JButton add = new JButton("add tab");
          JButton remove = new JButton("remove tab");
          TabbedPaneTest()
          {
              setLayout(new BorderLayout());
              JPanel p = new JPanel(new GridLayout(1,2));
              p.add(add);
              p.add(remove);
              add.addActionListener(this);
              remove.addActionListener(this);
              add(p, BorderLayout.NORTH);
              add(desktop, BorderLayout.CENTER); // where the real components would be
              add(tabs, BorderLayout.SOUTH);
              tabs.addTab("component", null, new DumbComponent());
          }
          public void actionPerformed(ActionEvent e)
          {
              if (e.getSource() == add) {
                  tabs.addTab("component", null, new DumbComponent());
                  // Add a real component in the desktop area...
              } else {
                  if (tabs.getSelectedIndex() != -1) {
                      // Remove the corresponding real component in the desktop area...
                      tabs.removeTabAt(tabs.getSelectedIndex());
                  }
              }
          }
          private class DumbComponent extends JComponent {
              DumbComponent() { super();}
          }
          public static void main(String args[])
          {
              JFrame frame = new JFrame("TabbedPane with empty components");
           frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
      JOptionPane.setRootFrame(frame);
              frame.getContentPane().add(new TabbedPaneTest());
              frame.pack();
              frame.setSize(new Dimension(300,150));
              frame.show();
          }
      }
      (Review ID: 93548)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: