public Dimension preferredLayoutSize(Container parent) {
		synchronized (parent.getTreeLock()) {
			Insets insets = parent.getInsets();

			int totalWidth = maxWidth - insets.left - insets.right;
			int height = 0;
			int width = 0;
			int maxHeightOfThisLine = 0;
			
			int componentCount = parent.getComponentCount();
			for(int i=0; i<componentCount; i++) {
				Component c = parent.getComponent(i);
				Dimension d = c.getPreferredSize();
				if(width + d.width < totalWidth || width == 0) { // also accept any first component on this line
					width += d.width + hGap;
					maxHeightOfThisLine = Math.max(maxHeightOfThisLine, d.height);
				} else { // this component must go onto the next line
					if(this.exactLineHeight > 0) {
						maxHeightOfThisLine = exactLineHeight;
					}
					height += maxHeightOfThisLine + vGap;
					maxHeightOfThisLine = d.height;
					width = d.width + hGap;
				}
			}
			height += maxHeightOfThisLine;
			return new Dimension(maxWidth, insets.top + insets.bottom + height);			
		}
	}