关键字:Draw2d GridLayout 布局管理器GridData
public class HelloWorld { public static void main(String args[]) { Shell shell = new Shell(); shell.setText("Draw2d Hello World"); shell.setSize(300, 300); shell.open(); // create content 4 shell. createContent4Shell(shell); while (!shell.isDisposed ()) { if (!Display.getDefault().readAndDispatch ()) Display.getDefault().sleep (); } } private static void createContent4Shell(Shell shell) { Figure container = new Figure(); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; container.setLayoutManager(gridLayout); Shape rect; rect = new RectangleFigure(); container.add(rect); GridData gridData = new GridData(); gridData.widthHint = 50; gridData.heightHint = 50; gridLayout.setConstraint(rect, gridData); rect = new RectangleFigure(); gridData = new GridData(); gridData.widthHint = 100; gridData.heightHint = 100; gridLayout.setConstraint(rect, gridData); container.add(rect); rect = new RectangleFigure(); gridData = new GridData(); gridData.widthHint = 150; gridData.heightHint = 150; gridLayout.setConstraint(rect, gridData); container.add(rect); LightweightSystem lws = new LightweightSystem(shell); lws.setContents(container); } }