Exemplo n.º 1
0
  /**
   * Lays out the container in the specified panel.
   *
   * @param parent the component which needs to be laid out
   */
  public void layoutContainer(Container parent) {
    for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
      Dimension size = comp.getPreferredSize();
      int width = ac.getWidth();
      if (width == -1) width = size.width;
      int height = ac.getHeight();
      if (height == -1) height = size.height;

      comp.setBounds(ac.x, ac.y, width, height);
    }
  }
Exemplo n.º 2
0
  /**
   * Calculates the preferred dimension for the specified panel given the components in the
   * specified parent container.
   *
   * @param parent the component to be laid out
   * @see #minimumLayoutSize
   */
  public Dimension preferredLayoutSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
      Dimension size = comp.getPreferredSize();

      int width = ac.getWidth();
      if (width == -1) width = size.width;
      int height = ac.getHeight();
      if (height == -1) height = size.height;

      if (ac.x + width > maxWidth) maxWidth = ac.x + width;
      if (ac.y + height > maxHeight) maxHeight = ac.y + height;
    }
    return new Dimension(maxWidth, maxHeight);
  }