int y = insets.top;
int preferredHeightAll = 0; for (int index = 0; index < children.length; index++) { preferredHeightAll += children[index].getPreferredSize().height; } double heightFactor = (double) innerSize.height / (double) preferredHeightAll;   int heightRemain = innerSize.height;
  public void layoutContainer(Container parent)  {    if (parent != container)      throw new AWTError("invalid parent");        Dimension size = parent.getSize();    Insets insets = parent.getInsets();    Dimension innerSize = new Dimension(size.width - insets.left                                        - insets.right, size.height                                        - insets.bottom - insets.top);    Component[] children = parent.getComponents();    if (isHorizontalIn(parent))      {        int x = insets.left;        for (int index = 0; index < children.length; index++)          {            Component comp = children[index];            Dimension sz = comp.getPreferredSize();            int width = sz.width;            int height = sz.height;            int cy = insets.top;            if (height > innerSize.height)              {                height = innerSize.height;              }            else              {                cy = (int) ((innerSize.height - height)                            * comp.getAlignmentY());              }                        comp.setSize(width, height);            comp.setLocation(x, cy);            x = x + width;                      }      }    else      {        int y = insets.top;                for (int index = 0; index < children.length; index++)          {            Component comp = children[index];            Dimension sz = comp.getPreferredSize();            int width = sz.width;            int height = sz.height;            int cx = insets.left;            if (width > innerSize.width)              {                width = innerSize.width;              }            else              {                cx = (int) ((innerSize.width - width) * comp.getAlignmentX());              }                        comp.setSize(width, height);            comp.setLocation(cx, y);            y = y + height;                      }      }      }