本文主要是介绍draw2d的布局,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
测试:
。
package test.draw2d.layout;import org.eclipse.draw2d.BorderLayout;public class LayoutShell extends Shell {/*** Launch the application.* * @param args*/public static void main(String args[]) {try {Display display = Display.getDefault();LayoutShell shell = new LayoutShell(display);shell.open();shell.layout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}} catch (Exception e) {e.printStackTrace();}}/*** Create the shell.* * @param display*/public LayoutShell(Display display) {super(display, SWT.SHELL_TRIM);createContents();}/*** Create contents of the shell.*/protected void createContents() {setText("SWT Application draw2d");setSize(400, 400);setLayout(new FillLayout());LightweightSystem lws = new LightweightSystem(this);Figure canvas = new Figure();BorderLayout borderLayout = new BorderLayout();borderLayout.setHorizontalSpacing(10);// BorderLayout分五块之间的间距borderLayout.setVerticalSpacing(10);// BorderLayout分五块之间的间距canvas.setLayoutManager(borderLayout);lws.setContents(canvas);// ----------------GridData--left---right-------GridData gridDataLeftRight = new GridData();gridDataLeftRight.horizontalAlignment = SWT.FILL;gridDataLeftRight.verticalAlignment = SWT.FILL;gridDataLeftRight.grabExcessHorizontalSpace = true;gridDataLeftRight.grabExcessVerticalSpace = true;// ----------------left------------Figure canvasLeft = new Figure();canvasLeft.setSize(100, 0);// 有子元素按子元素的大小canvas.add(canvasLeft, BorderLayout.LEFT);canvasLeft.setLayoutManager(new GridLayout());RectangleFigure rectangleFigure = new RectangleFigure();rectangleFigure.setBackgroundColor(ColorConstants.yellow);rectangleFigure.setSize(50, 0);// 没有子元素按父元素的大小canvasLeft.add(rectangleFigure, gridDataLeftRight);// --------------right--------------Figure canvasRight = new Figure();canvasRight.setSize(100, 0);canvas.add(canvasRight, BorderLayout.RIGHT);canvasRight.setLayoutManager(new GridLayout());rectangleFigure = new RectangleFigure();rectangleFigure.setBackgroundColor(ColorConstants.yellow);rectangleFigure.setSize(50, 0);canvasRight.add(rectangleFigure, gridDataLeftRight);// ----------------GridData--top---bottom-------GridData gridDataTopBottom = new GridData();gridDataTopBottom.horizontalAlignment = SWT.FILL;gridDataTopBottom.verticalAlignment = SWT.FILL;gridDataTopBottom.grabExcessHorizontalSpace = true;gridDataTopBottom.grabExcessVerticalSpace = true;gridDataTopBottom.horizontalIndent = 100;// --------------top--------------Figure canvasTop = new Figure();canvasTop.setSize(0, 100);canvas.add(canvasTop, BorderLayout.TOP);canvasTop.setLayoutManager(new GridLayout());rectangleFigure = new RectangleFigure();rectangleFigure.setBackgroundColor(ColorConstants.blue);rectangleFigure.setSize(0, 50);canvasTop.add(rectangleFigure, gridDataTopBottom);// -------------bottom---------------Figure canvasBottom = new Figure();canvasBottom.setSize(0, 100);canvas.add(canvasBottom, BorderLayout.BOTTOM);canvasBottom.setLayoutManager(new GridLayout());rectangleFigure = new RectangleFigure();rectangleFigure.setBackgroundColor(ColorConstants.blue);rectangleFigure.setSize(0, 50);canvasBottom.add(rectangleFigure, gridDataTopBottom);// ------------center----------------Figure canvasCenter = new Figure();// canvasCenter.setSize(0, 0);canvas.add(canvasCenter, BorderLayout.CENTER);canvasCenter.setLayoutManager(new GridLayout());rectangleFigure = new RectangleFigure();rectangleFigure.setBackgroundColor(ColorConstants.red);// rectangleFigure.setSize(50, 40);canvasCenter.add(rectangleFigure, gridDataLeftRight);}@Overrideprotected void checkSubclass() {// Disable the check that prevents subclassing of SWT components}}
。
这篇关于draw2d的布局的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!