private Dimension getLayoutSize(Container parent, int hGap, boolean layout) { Insets insets = parent.getInsets(); int lineMaxX = 0; int lineY = 0; int currentY = 0; int currentX = 0; int maxY = 0; int maxX = 0; int topMargin = 0; int leftMargin = 0; Dimension d; Component[] components = parent.getComponents(); for (int i = 0; i < components.length; i++) { if (components[i] instanceof CPLabel) { topMargin = 20; leftMargin = 0; currentY = lineY; currentX = lineMaxX + hGap; lineMaxX = currentX; } else if (components[i] instanceof CPCheckBox) { topMargin = 0; leftMargin = 0; } if (components[i] instanceof CRLF) { lineY = maxY; lineMaxX = 0; } else { // It's not a CRLF, lay it out. d = components[i].getPreferredSize(); if (layout) { components[i].setBounds( insets.left + leftMargin + currentX, insets.top + topMargin + currentY, d.width, d.height); } currentY += topMargin + d.height; lineMaxX = Math.max(lineMaxX, leftMargin + currentX + d.width); maxX = Math.max(maxX, lineMaxX); maxY = Math.max(maxY, topMargin + currentY + d.height); } } return new Dimension(insets.left + maxX + insets.right, insets.top + maxY + insets.bottom); }