Component selectedComponent = tabPane.getComponentAt(selectedIndex);
Component selectedComponent = null; if (selectedIndex >= 0) selectedComponent = tabPane.getComponentAt(selectedIndex);
    public void layoutContainer(Container parent)    {      calculateLayoutInfo();      int tabPlacement = tabPane.getTabPlacement();      Insets insets = tabPane.getInsets();      int selectedIndex = tabPane.getSelectedIndex();      Component selectedComponent = tabPane.getComponentAt(selectedIndex);      // The RI doesn't seem to change the component if the new selected      // component == null. This is probably so that applications can add      // one single component for every tab.       if (selectedComponent != null)        {          setVisibleComponent(selectedComponent);        }      int childCount = tabPane.getComponentCount();      if (childCount > 0)        {          int compX;          int compY;          int tabAreaWidth = 0;          int tabAreaHeight = 0;          switch (tabPlacement)          {            case LEFT:              tabAreaWidth = calculateTabAreaWidth(tabPlacement, runCount,                                                   maxTabWidth);              compX = tabAreaWidth + insets.left + contentBorderInsets.left;              compY = insets.top + contentBorderInsets.top;              break;            case RIGHT:              tabAreaWidth = calculateTabAreaWidth(tabPlacement, runCount,                                                   maxTabWidth);              compX = insets.left + contentBorderInsets.left;              compY = insets.top + contentBorderInsets.top;              break;            case BOTTOM:               tabAreaHeight = calculateTabAreaHeight(tabPlacement, runCount,                                                     maxTabHeight);              compX = insets.left + contentBorderInsets.left;              compY = insets.top + contentBorderInsets.top;              break;            case TOP:            default:              tabAreaHeight = calculateTabAreaHeight(tabPlacement, runCount,                                                     maxTabHeight);              compX = insets.left + contentBorderInsets.left;              compY = tabAreaHeight + insets.top + contentBorderInsets.top;          }          Rectangle bounds = tabPane.getBounds();          int compWidth = bounds.width - tabAreaWidth - insets.left                          - insets.right - contentBorderInsets.left                          - contentBorderInsets.right;          int compHeight = bounds.height - tabAreaHeight - insets.top                           - insets.bottom - contentBorderInsets.top                           - contentBorderInsets.bottom;          for (int i = 0; i < childCount; ++i)            {              Component c = tabPane.getComponent(i);              c.setBounds(compX, compY, compWidth, compHeight);            }        }    }