@Override
    public void layoutContainer(Container parent) {
      myShowHiddenTabsButton.setBounds(new Rectangle());
      int selectedIndex = tabPane.getSelectedIndex();
      Rectangle selectedRectBackup;
      if (useSelectedRectBackup && selectedIndex != -1 && rects != null && rects.length > selectedIndex) {
        selectedRectBackup = new Rectangle(rects[selectedIndex]);
      }
      else {
        selectedRectBackup = null;
      }

      myDelegate.layoutContainer(parent);
      if (selectedRectBackup != null) {
        rects[selectedIndex] = selectedRectBackup;
      }

      useSelectedRectBackup = true;
      Field obj = ReflectionUtil.getDeclaredField(BasicTabbedPaneUI.class, "tabScroller");
      if (obj != null) {
        Object obj1 = ReflectionUtil.getFieldValue(obj, DarculaTabbedPaneUI.this);
        if (obj1 != null) {
          Field obj2 = ReflectionUtil.getDeclaredField(obj1.getClass(), "croppedEdge");
          if (obj2 != null) {
            Object obj3 = ReflectionUtil.getFieldValue(obj2, obj1);
            if (obj3 != null) {
              ReflectionUtil.resetField(obj3, "shape");
            }
          }
        }
      }

      if (myShowHiddenTabsButton != null && !myHiddenArrowButtons.isEmpty()) {
        Rectangle bounds = null;
        for (Component button : myHiddenArrowButtons) {
          bounds = bounds == null ? button.getBounds() : bounds.union(button.getBounds());
          button.setBounds(new Rectangle());
        }
        JViewport viewport = getScrollableTabViewport();
        // the last tab is selected, BasicTabbedPaneUI fails a bit
        if (bounds.isEmpty() && viewport != null) {
          Rectangle viewportBounds = viewport.getBounds();
          if (isTopBottom()) {
            int buttonsWidth = 2 * myHiddenArrowButtons.get(0).getPreferredSize().width;
            viewportBounds.width -= buttonsWidth;
            viewport.setBounds(viewportBounds);
            ensureSelectedTabIsVisible();
            bounds = new Rectangle(viewport.getX() + viewport.getWidth(), viewport.getY(), buttonsWidth, viewport.getHeight());
          }
          else {
            int buttonHeight = 2 * myHiddenArrowButtons.get(0).getPreferredSize().height;
            viewportBounds.height -= buttonHeight;
            viewport.setBounds(viewportBounds);
            ensureSelectedTabIsVisible();
            bounds = new Rectangle(viewport.getX(), viewport.getY() + viewport.getHeight(), viewport.getWidth(), buttonHeight);
          }
          myShowHiddenTabsButton.setBounds(bounds);
          return;
        }

        int placement = tabPane.getTabPlacement();
        int size;
        if (placement == TOP || placement == BOTTOM) {
          size = preferredTabAreaHeight(tabPane.getTabPlacement(), tabPane.getWidth());
        }
        else {
          size = preferredTabAreaWidth(tabPane.getTabPlacement(), tabPane.getWidth());
        }
        switch (placement) {
          case TOP:
            bounds.y -= size - bounds.height;
          case BOTTOM: {
            bounds.height = size;
            break;
          }
          case LEFT: {
            bounds.x -= size - bounds.width;
          }
          case RIGHT: {
            bounds.width = size;
            break;
          }
        }
        myShowHiddenTabsButton.setBounds(bounds);
      }
    }
@Override
    public void layoutContainer(Container parent)