protected Dimension doLayout(Container target) {

		// Pass 1 - get preferred sizes
		minw = minh = 0;
		curComps = target.getComponents();
		for (int i = 0; i<curComps.length; i++) {
			Component tc = curComps[i];
			Dimension d = tc.getPreferredSize();
			minw = Math.max(minw, d.width);
			minh = Math.max(minh, d.height);
		}

		// Pass 2 - move & resize components
		int x = hPadding, y = vPadding;
		for (int i = 0; i<curComps.length; i++) {
			Component tc = curComps[i];
			Dimension d = tc.getPreferredSize();
			int cx, cy, cw, ch;
			switch (alignment) {
			case X_AXIS:
				if (tc instanceof Spacer)
					cw = d.width;
				else
					cw = minw;
				ch = minh; // d.height;
				cx = x;
				x += cw+hPadding;
				cy = vPadding;
				y  = ch;
				break;
			case Y_AXIS:
				cw = minw; // d.width;
				if (tc instanceof Spacer)
					ch = d.height;
				else
					ch = minh;
				cx = hPadding;
				x = cw;
				cy = y;
				y += ch+vPadding;
				break;
			default:
				throw new IllegalArgumentException("Invalid alignment");
			}
			tc.setBounds(cx, cy, cw, ch);
		}
		switch (alignment) {
			case X_AXIS:
				return new Dimension(x, y+2*vPadding);
			case Y_AXIS:
				return new Dimension(x+2*hPadding, y);
			default:
				throw new IllegalArgumentException("Invalid alignment");
		}
	}