void (Container parent) { Insets insets = parent.getInsets(); int height = parent.getHeight() - insets.top - insets.bottom; int x = insets.left; int count = parent.getComponentCount(); for (int i = 0; i < count; i++) { Component component = parent.getComponent(i); if (!component.isVisible()) { continue; } Dimension size = component.getPreferredSize(); component.setBounds(x, insets.top + (height - size.height) / 2, size.width, size.height); x += size.width + myOffset; } }