int maxX = 0; int maxY = 0;
java.awt.Insets insets = p.getInsets();
  public Dimension maximumLayoutSize(Container p)  {    int maxX = 0;    int maxY = 0;    int offsetX = p.getInsets().left;    int offsetY = p.getInsets().right;    Component[] components = p.getComponents();    for (int index = 0; index < components.length; index++)      {        Component c = components[index];        Constraints constraints = getConstraints(c);        int x = constraints.getX().getMaximumValue();        int y = constraints.getY().getMaximumValue();        int width = constraints.getWidth().getMaximumValue();        int height = constraints.getHeight().getMaximumValue();        int rightEdge = offsetX + x + width;        if (rightEdge > maxX)          maxX = rightEdge;        int bottomEdge = offsetY + y + height;        if (bottomEdge > maxY)          maxY = bottomEdge;      }    return new Dimension(maxX, maxY);  }