Rectangle (@NotNull JComponent component, @NotNull Rectangle bounds) { Dimension size = component.getPreferredSize(); int width = Math.min(size.width, bounds.width); return component == getComponent() ? new Rectangle(bounds.x, bounds.y, width, bounds.height) : new Rectangle(bounds.x + bounds.width - width, bounds.y, width, bounds.height); }