public static void center(Component componentToMove,Component componentToCenterOn){
  Dimension componentToCenterOnSize=componentToCenterOn.getSize();
  componentToMove.setLocation(componentToCenterOn.getX() + ((componentToCenterOnSize.width - componentToMove.getWidth()) / 2),componentToCenterOn.getY() + ((componentToCenterOnSize.height - componentToMove.getHeight()) / 2));
}

public static void center ( Component componentToMove , Component componentToCenterOn ) { Dimension componentToCenterOnSize = componentToCenterOn . getSize ( ) ; componentToMove . setLocation ( componentToCenterOn . getX ( ) + ( ( componentToCenterOnSize . width - componentToMove . getWidth ( ) ) / 2 ) , componentToCenterOn . getY ( ) + ( ( componentToCenterOnSize . height - componentToMove . getHeight ( ) ) / 2 ) ) ; }
centers the first component on the second
