6.2 The row layout

6.2 The row layout
可以多行/列显示。

package com.swtjface.Ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6RowLayoutComposite extends Composite {
public Ch6RowLayoutComposite(Composite parent) {
super(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
setLayout(layout);
for (int i = 0; i < 16; ++i) {
Button button = new Button(this, SWT.NONE);
button.setText("Sample Text");
}
}
}

wrap——默认为true,若设为false,所有的controls都在同一行。
pack——默认为true.使所有的child controls都大小一样。
justify——默认为false. 若为true,每一行的control都会以间隔相同的方式排列。

RowData
可以通过setLayoutData()来设定每个control的大小,如:button.setLayoutData(new RowData(200 + 5 * i, 20 + i));

你可能感兴趣的:(6.2 The row layout)