Draw2d 学习笔记二 BorderLayout

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 BorderLayout());
		
		panel.add(new Label("CENTER"), BorderLayout.CENTER);
		panel.add(new Label("TOP"), BorderLayout.TOP);
		panel.add(new Label("LEFT"), BorderLayout.LEFT);
		panel.add(new Label("RIGHT"), BorderLayout.RIGHT);
		panel.add(new Label("BOTTOM"), BorderLayout.BOTTOM);
		
		LightweightSystem lws = new LightweightSystem(shell);
		lws.setContents(panel);
	}
}

 

 

这里的BorderLayout布局管理器的用法基本上和AWT中的用法是一样的。SWT中没有BorderLayout布局,BorderLayout可以没有LEFT、RIGHT和BOTTOM,其它会把多余的空间占据。

你可能感兴趣的:(draw2d)