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

[macosx] TabbedPaneUI.getTabBounds works only after tabs are visible or call to pack().

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.9.4

      A DESCRIPTION OF THE PROBLEM :
      With previous versions of JDK (7), TabbedPaneUI.getTabBounds always returned the bounds regardless if JTabbedPane has been visible or not, now with JDK8 TabbedPaneUI.getTabBounds only returns the bounds for the first tab and for the next tabs always returns null, it only returns the bounds of the other tabs until the JTabbedPane is visible or if pack() has been called before getTabBounds.



      REGRESSION. Last worked in version 7u60

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JTabbedPane
      Add two tabs.
      Call getTabBounds on TabbedPaneUI for each tab.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      getTabBounds should return the bounds for each tab.
      ACTUAL -
      getTabBounds only return the bounds for the first tab.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      package components;

      import javax.swing.JTabbedPane;
      import javax.swing.ImageIcon;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JFrame;
      import javax.swing.JComponent;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.GridLayout;
      import java.awt.event.KeyEvent;
      import java.lang.Thread;

      public class TabbedPaneDemo extends JPanel {
             
          private static void createAndShowGUI() {
              JFrame frame = new JFrame("TabbedPaneDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
              JTabbedPane tabbedPane = new JTabbedPane();
              
              JPanel panel1 = new JPanel(false);
              JLabel filler1 = new JLabel("Tab 1");
              filler1.setHorizontalAlignment(JLabel.CENTER);
              panel1.setLayout(new GridLayout(1, 1));
              panel1.add(filler1);
              
              tabbedPane.addTab("Tab 1", panel1);
              tabbedPane.setSelectedComponent(panel1);
              
              // This line prints the bounds on JDK 7 and JDK8
              System.out.println("Tab bounds 1: " + tabbedPane.getUI().getTabBounds(tabbedPane, 0));
              
              JPanel panel2 = new JPanel(false);
              JLabel filler2 = new JLabel("Tab 2");
              filler2.setHorizontalAlignment(JLabel.CENTER);
              panel2.setLayout(new GridLayout(1, 1));
              panel2.add(filler2);
              
              tabbedPane.addTab("Tab 2", panel2);
              tabbedPane.setSelectedComponent(panel2);
                   
           // This line prints the bounds only on JDK 7.
              System.out.println("Tab bounds 2: " + tabbedPane.getUI().getTabBounds(tabbedPane, 1));
                      
              frame.add(tabbedPane, BorderLayout.CENTER);
              frame.pack();
              
              // This line prints the bounds on JDK 7 and JDK8
              System.out.println("Tab bounds 2: " + tabbedPane.getUI().getTabBounds(tabbedPane, 1));
              
              frame.setVisible(true);
          }
          
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
      createAndShowGUI();
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Validate if the returned bounds is null.

            alexsch Alexandr Scherbatiy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: