void (@NotNull Dimension sizeToFit, @NotNull List<? extends Rectangle> bounds) { final int componentCount = getComponentCount(); LOG.assertTrue(componentCount <= bounds.size()); final boolean actualLayout = bounds == myComponentBounds; if (actualLayout) { myAutoPopupRec = null; } int autoButtonSize = AllIcons.Ide.Link.getIconWidth(); boolean full = false; final Insets insets = getInsets(); int widthToFit = sizeToFit.width - insets.left - insets.right; int heightToFit = sizeToFit.height - insets.top - insets.bottom; if (myOrientation == SwingConstants.HORIZONTAL) { int eachX = 0; int maxHeight = heightToFit; for (int i = 0; i < componentCount; i++) { final Component eachComp = getComponent(i); final boolean isLast = i == componentCount - 1; final Rectangle eachBound = new Rectangle(getChildPreferredSize(i)); maxHeight = Math.max(eachBound.height, maxHeight); if (!full) { boolean inside = isLast ? eachX + eachBound.width <= widthToFit : eachX + eachBound.width + autoButtonSize <= widthToFit; if (inside) { if (eachComp == mySecondaryActionsButton) { assert isLast; if (sizeToFit.width != Integer.MAX_VALUE && !myNoGapMode) { eachBound.x = sizeToFit.width - insets.right - eachBound.width; eachX = (int)eachBound.getMaxX() - insets.left; } else { eachBound.x = insets.left + eachX; } } else { eachBound.x = insets.left + eachX; eachX += eachBound.width; } eachBound.y = insets.top; } else { full = true; } } if (full) { if (myAutoPopupRec == null) { myAutoPopupRec = new Rectangle(insets.left + eachX, insets.top, widthToFit - eachX, heightToFit); myFirstOutsideIndex = i; } eachBound.x = Integer.MAX_VALUE; eachBound.y = Integer.MAX_VALUE; } bounds.get(i).setBounds(eachBound); } for (final Rectangle r : bounds) { if (r.height < maxHeight) { r.y += (maxHeight - r.height) / 2; } } } else { int eachY = 0; for (int i = 0; i < componentCount; i++) { final Rectangle eachBound = new Rectangle(getChildPreferredSize(i)); if (!full) { boolean outside; if (i < componentCount - 1) { outside = eachY + eachBound.height + autoButtonSize < heightToFit; } else { outside = eachY + eachBound.height < heightToFit; } if (outside) { eachBound.x = insets.left; eachBound.y = insets.top + eachY; eachY += eachBound.height; } else { full = true; } } if (full) { if (myAutoPopupRec == null) { myAutoPopupRec = new Rectangle(insets.left, insets.top + eachY, widthToFit, heightToFit - eachY); myFirstOutsideIndex = i; } eachBound.x = Integer.MAX_VALUE; eachBound.y = Integer.MAX_VALUE; } bounds.get(i).setBounds(eachBound); } } }