Rectangle (@NotNull JComponent container) { Dimension size = container.getSize(); Dimension iconSize = getPreferredSize(); return new Rectangle((size.width - iconSize.width) / 2, (size.height - iconSize.height) / 2, iconSize.width, iconSize.height); }