Title: RE: Layout-Problems

pardon me if my description wasn't good....
I figured outmy problem.

all the collumns are independently size, but they all line up
by making the largest item in the, say, 2nd spot in the layout dictate what all the other layouts use for their side on the 2nd collunm...

I don't think I'm explaining my self good enough...
here's the code:
(it still needs to be cleaned up... and componentWidth needs to be dynamic)
any wordS?
rev aaron
www.returntothepit.com


import java.awt.*;
import javax.swing.*;
import java.util.Vector;

public class MTOLayout implements LayoutManager
{
    private int minWidth = 0, minHeight = 0;
    private int preferredWidth = 0, preferredHeight = 0;
    static int []componentWidth = new int [] {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
    static int componentHeight = 0;

    public MTOLayout() {
    }


    /* Required by LayoutManager. */
    public void addLayoutComponent(String name, Component comp) {
    }

    /* Required by LayoutManager. */
    public void removeLayoutComponent(Component comp) {
    }

    private void setSizes(Container parent) {
        int nComps = parent.getComponentCount();
        Dimension d = null;

        //Reset preferred/minimum width and height.
        preferredWidth = 10;
        preferredHeight = 30;
        minWidth = 10;
        minHeight = 25;
    }


    /* Required by LayoutManager. */
    public Dimension minimumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int nmembers = target.getComponentCount();

        for (int i = 0 ; i < nmembers ; i++) {
            Component m = target.getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getMinimumSize();
                dim.height = 0;
                if (i > 0) {
                    dim.width += 0;
                }
                dim.width += d.width;
            }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right + 0;
        dim.height += 0;
        return dim;
      }
    }


    /* Required by LayoutManager. */
    /*
     * This is called when the panel is first displayed,
     * and every time its size changes.
     * Note: You CAN'T assume preferredLayoutSize or
     * minimumLayoutSize will be called -- in the case
     * of applets, at least, they probably won't be.
     */
    public void layoutContainer(Container target) {
      synchronized (target.getTreeLock())
      {
        int numb = target.getComponentCount();
        for(int i = 0 ; i < numb; i++)
        {
          JComponent m = (JComponent)target.getComponent(i);
          componentWidth[i] =  Math.max((int)m.getPreferredSize().getWidth(), componentWidth[i]);
          componentHeight =  Math.max((int)m.getPreferredSize().getHeight(), componentHeight);
                  m.setSize(componentWidth[i], componentHeight);
          moveComponents(target);
       }
      }
    }

    public Dimension preferredLayoutSize(Container target) {
      synchronized (target.getTreeLock())
      {

        int numb = target.getComponentCount();
        int x = 0;
        for(int i = 0 ; i < numb; i++)
        {
          JComponent m = (JComponent)target.getComponent(i);
          componentWidth[i] =  Math.max((int)m.getPreferredSize().getWidth(), componentWidth[i]); 
          componentHeight =  Math.max((int)m.getPreferredSize().getHeight(), componentHeight);
                  m.setSize(componentWidth[i], componentHeight);
          x += componentWidth[i];
          moveComponents(target);
       }
        return new Dimension(500,componentHeight);
      }
    }
    private void moveComponents(Container target)
    {
      Component m = target.getComponent(0);
      int x = 0;
      for(int i = 0; i < target.getComponentCount();i++)
      {                  
        m = target.getComponent(i);
        m.setLocation(x, 0);
        x += m.getWidth();
     }
    }
}

Reply via email to