code: public static void centerComponent (Component a, Component b)
      {
          Dimension asize = a.getSize(), bsize = b.getSize();
          b.setLocation((asize.width - bsize.width) / 2, (asize.height - bsize.height) / 2);
      }
docs: Centers component <code>b</code> within component <code>a</code>.