Ejemplo n.º 1
0
  /**
   * 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);
        }
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * 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));
 }