public class HelloWorld {
public static void main(String args[]) {
Shell shell = new Shell();
shell.setText("Draw2d Hello World");
shell.pack(); shell.open();
// create content 4 shell.
createContent4Shell(shell);
while (!shell.isDisposed ()) {
if (!Display.getDefault().readAndDispatch ())
Display.getDefault().sleep ();
}
}
private static void createContent4Shell(Shell shell) {
IFigure panel = new Panel();
panel.setLayoutManager(new FlowLayout());
for(int i=0; i<100; i++) {
panel.add(new Label("Label " + i));
}
LightweightSystem lws = new LightweightSystem(shell);
lws.setContents(panel);
}
}
FlowLayout布局管理器在swt中也有对应的布局管理器,应用起来也是比较的简单。可以根据外部的窗口大小的变化自动调整内部的布局。
/**
* Lays out children in rows or columns, wrapping when the current row/column is filled.
* The aligment and spacing of rows in the parent can be configured. The aligment and
* spacing of children within a row can be configured.
*/