void (JComponent comp, Container parent) { final Rectangle compBounds = comp.getBounds(); Insets insets = parent.getInsets(); int compHeight = comp.getPreferredSize().height; final int parentHeight = parent.getHeight() - insets.top - insets.bottom; if (compHeight > parentHeight) { compHeight = parentHeight; } int y = (int)Math.floor(parentHeight / 2.0 - compHeight / 2.0) + insets.top; comp.setBounds(compBounds.x, y, compBounds.width, compHeight); }