RowLayout(行布局)中的控件们可以设定固定的间距,随着列宽的增加,行内的控件数增加,适合做图片墙。
import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;public class RowLayoutExample {
public static void main(String[] args) {
Button button;
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("RowLayout Example");
shell.setBounds(100, 100, 400, 100);
RowLayout layout = new RowLayout();
layout.marginLeft = 10;
layout.marginRight = 10;
layout.marginTop = 10;
layout.marginBottom = 10;
layout.spacing = 10;
shell.setLayout(layout);
for (int i = 1; i <= 20; i++) {
button = new Button(shell, SWT.PUSH);
button.setText("B" + i);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
System.out.println(((Button) event.widget).getText()
+ " was clicked!");
}
});
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
效果如下:
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于