public Dimension preferredLayoutSize(Container parent) {
    Component[] components = parent.getComponents();
    left = 0;
    right = 0;
    height = 0;
    for (int i = 0; i < components.length; i += 2) {
        Component cleft = components[i];
        Component cright = components[i + 1];
        
        Dimension dleft = cleft.getPreferredSize();
        Dimension dright = cright.getPreferredSize();
        left = Math.max(left, dleft.width);
        right = Math.max(right, dright.width);
        height = height + Math.max(dleft.height, dright.height);
    }
    return new Dimension(left + GAP + right, height);
}