{
if (parent.getComponentCount() > 0)
{
final Insets insets = parent.getInsets();
final Dimension parentSize = parent.getSize();
final Component component = parent.getComponent(0);
final Dimension componentSize = component.getPreferredSize();
final int xx = insets.left + (
Math.max((parentSize.width - insets.left - insets.right
- componentSize.width) / 2, 0)
);
final int yy = insets.top + (
Math.max((parentSize.height - insets.top - insets.bottom
- componentSize.height) / 2, 0));
component.setBounds(xx, yy, componentSize.width,
componentSize.height);
}
}
}