/**
   * Lays out the container.
   *
   * @param target The container which needs to be laid out.
   */
  public void layoutContainer(Container target) {
    Insets insets;
    int x;
    int y;
    int count;
    int width;
    Component component;
    Dimension dimension;

    synchronized (target.getTreeLock()) {
      insets = target.getInsets();
      x = insets.left;
      y = insets.top;
      count = target.getComponentCount();
      width = 0;
      for (int i = 0; i < count; i++) {
        component = target.getComponent(i);
        if (component.isVisible()) {
          dimension = component.getPreferredSize();
          width = Math.max(width, dimension.width);
          component.setSize(dimension.width, dimension.height);
          component.setLocation(x, y);
          y += dimension.height;
        }
      }
      // now set them all to the same width
      for (int i = 0; i < count; i++) {
        component = target.getComponent(i);
        if (component.isVisible()) {
          dimension = component.getSize();
          dimension.width = width;
          component.setSize(dimension.width, dimension.height);
        }
      }
    }
  }
 /**
  * A very nice trick is to center dialog with their parent.
  *
  * @param parent The parent <code>Component</code>
  * @param child The <code>Component</code> to center
  */
 public static void centerComponentChild(Component parent, Component child) {
   Rectangle par = parent.getBounds();
   Rectangle chi = child.getBounds();
   child.setLocation(
       new Point(par.x + (par.width - chi.width) / 2, par.y + (par.height - chi.height) / 2));
 }
 /**
  * A very nice trick is to center windows on screen, this method helps you to to that.
  *
  * @param compo The <code>Component</code> to center
  */
 public static void centerComponent(Component compo) {
   compo.setLocation(
       new Point(
           (getScreenDimension().width - compo.getSize().width) / 2,
           (getScreenDimension().height - compo.getSize().height) / 2));
 }