void (@NotNull JComponent container) { Rectangle newBounds = calculateBounds(container); if (!newBounds.equals(getBounds())) { setBounds(newBounds); // painting problems with scrollpane // repaint shouldn't be called from paint method SwingUtilities.invokeLater(() -> container.repaint()); } }