Bug 308095 [Forms] ColumnLayout does not layout widgets correctly
I'm using eclipse 3.6M6 When given a large number of widgets >=150 (approx), ColumnLayout does not render them in the correct order as expected. In appears that the layout renders all widgets in columns (top to bottom) and 'overflows' into the next column until there is no space left to render another column (or the max columns set on the layout) Here's a test case to reproduce and a screenshot. The screenshot shows how the label order is screwed up at label numbered 22 (highlighted) where the layout breaks the rendering to the next column but comes back to rendering label number 155 in the same column. package eclipse.bugs; import org.eclipse.jface.layout.PixelConverter; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.forms.widgets.ColumnLayout; import org.eclipse.ui.forms.widgets.ColumnLayoutData; import org.eclipse.ui.forms.widgets.Hyperlink; public class ColumnLayoutTest { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); ColumnLayout layout = new ColumnLayout(); layout.maxNumColumns = 20; layout.minNumColumns = 1; composite.setLayout(layout); // create 200 widgets, labels, hyperlinks, whatever for (int i = 1; i < 200; i++) { Hyperlink h = new Hyperlink(composite, SWT.NONE); // label.setLayoutData(); String text = i + " - Label"; h.setText(text); PixelConverter pixelConverter = new PixelConverter(h); int width = pixelConverter.convertWidthInCharsToPixels(text.length()); ColumnLayoutData layoutData = new ColumnLayoutData(width); h.setLayoutData(layoutData); } shell.setSize(600, 900); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ColumnLayout.java
import org.eclipse.swt.widgets.Layout;
/**
 * This layout manager arranges children of the composite parent in vertical
 * columns. All the columns are identical size and children are stretched
 * horizontally to fill the column width. The goal is to give layout some
 * reasonable range of column numbers to allow it to handle various parent
 * widths. That way, column number will drop to the lowest number in the range
 * when width decreases, and grow up to the highest number in the range when
 * allowed by the parent width.
 * <p>
 * In addition, the layout attempts to 'fill the space' equally i.e. to avoid
 * large gaps at the and of the last column.
 * <p>
 * Child controls are layed out according to their 'natural' (preferred) size.
 * For 'stretchy' controls that do not have natural preferred size, it is
 * possible to set width and/or height hints using ColumnLayoutData objects.
 * 
 * @see ColumnLayoutData
 * @since 3.0
 */
public final class ColumnLayout extends Layout implements ILayoutExtension {
	/**
	 * Minimum number of columns (default is 1).
	 */
	public int minNumColumns = 1;
	/**
	 * Maximum number of columns (default is 3).
	 */
	public int maxNumColumns = 3;
	/**