FileDocCategorySizeDatePackage
ColumnLayout.javaAPI DocExample4994Sat Jun 02 02:39:52 BST 2001None

ColumnLayout

public class ColumnLayout extends Object implements LayoutManager2
This LayoutManager arranges the components into a column. Components are always given their preferred size. When you create a ColumnLayout, you may specify four values: margin_height -- how much space to leave on left and right margin_width -- how much space to leave on top and bottom spacing -- how much vertical space to leave between items alignment -- the horizontal position of the components: ColumnLayout.LEFT -- left-justify the components ColumnLayout.CENTER -- horizontally center the components ColumnLayout.RIGHT -- right-justify the components You never call the methods of a ColumnLayout object. Just create one and make it the layout manager for your container by passing it to the addLayout() method of the Container object.

Fields Summary
protected int
margin_height
protected int
margin_width
protected int
spacing
protected int
alignment
public static final int
LEFT
public static final int
CENTER
public static final int
RIGHT
Constructors Summary
public ColumnLayout(int margin_height, int margin_width, int spacing, int alignment)
The constructor. See comment above for meanings of these arguments


              
      
                           
    this.margin_height = margin_height;
    this.margin_width = margin_width;
    this.spacing = spacing;
    this.alignment = alignment;
  
public ColumnLayout()
A default constructor that creates a ColumnLayout using 5-pixel margin width and height, 5-pixel spacing, and left alignment

 this(5, 5, 5, LEFT); 
Methods Summary
public voidaddLayoutComponent(java.lang.String constraint, java.awt.Component comp)

public voidaddLayoutComponent(java.awt.Component comp, java.lang.Object constraint)

public floatgetLayoutAlignmentX(java.awt.Container parent)

 return 0.5f; 
public floatgetLayoutAlignmentY(java.awt.Container parent)

 return 0.5f; 
public voidinvalidateLayout(java.awt.Container parent)

public voidlayoutContainer(java.awt.Container parent)
The method that actually performs the layout. Called by the Container

    Insets insets = parent.getInsets();
    Dimension parent_size = parent.getSize();
    Component kid;
    int nkids = parent.getComponentCount();
    int x0 = insets.left + margin_width;
    int x;
    int y = insets.top + margin_height;

    for(int i = 0; i < nkids; i++) {
      kid = parent.getComponent(i);
      if (!kid.isVisible()) continue;
      Dimension pref = kid.getPreferredSize();
      switch(alignment) {
      default:
      case LEFT:   x = x0; break;
      case CENTER: x = x0 + (parent_size.width - pref.width)/2; break;
      case RIGHT:  x = parent_size.width-insets.right-margin_width-pref.width;
                   break;
      }
      kid.setBounds(x, y, pref.width, pref.height);
      y += pref.height + spacing;
    }
  
protected java.awt.DimensionlayoutSize(java.awt.Container parent, int sizetype)

    int nkids = parent.getComponentCount();
    Dimension size = new Dimension(0,0);
    Insets insets = parent.getInsets();
    int num_visible_kids = 0;

    // Compute maximum width and total height of all visible kids
    for(int i = 0; i < nkids; i++) {
      Component kid = parent.getComponent(i);
      Dimension d;
      if (!kid.isVisible()) continue;
      num_visible_kids++;
      if (sizetype == 1) d = kid.getPreferredSize();
      else if (sizetype == 2) d = kid.getMinimumSize();
      else d = kid.getMaximumSize();
      if (d.width > size.width) size.width = d.width;
      size.height += d.height;
    }

    // Now add in margins and stuff
    size.width += insets.left + insets.right + 2*margin_width;
    size.height += insets.top + insets.bottom + 2*margin_height;
    if (num_visible_kids > 1)
      size.height += (num_visible_kids - 1) * spacing;
    return size;
  
public java.awt.DimensionmaximumLayoutSize(java.awt.Container parent)
The Container calls this to find out how big the layout can be

    return layoutSize(parent, 3);
  
public java.awt.DimensionminimumLayoutSize(java.awt.Container parent)
The Container calls this to find out how big the layout must be

    return layoutSize(parent, 2);
  
public java.awt.DimensionpreferredLayoutSize(java.awt.Container parent)
The Container calls this to find out how big the layout should to be

    return layoutSize(parent, 1);
  
public voidremoveLayoutComponent(java.awt.Component comp)