读书人

SWT 中Button跟Label重叠放置

发布时间: 2012-09-01 09:33:02 作者: rapoo

SWT 中Button和Label重叠放置

写了一个小例子:

?

public class Snippet206 {public static void main(String[] args) {Display display = new Display();Shell shell = new Shell(display);Image image1 = display.getSystemImage(SWT.ICON_QUESTION);Image image2 = new Image(display,image1.getImageData().scaledTo(16, 16));Color color = new Color(null, 213, 222, 246);shell.setLayout(new GridLayout(3, false));new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));Composite comp = new Composite(shell, SWT.BORDER);comp.setLayoutData(new GridData(GridData.FILL_BOTH));/* ******************************** */comp.setLayout(new FormLayout());FormData formData;// fill action to leftint buttonSpace = 5;{Composite comp1 = new Composite(comp, SWT.NONE);formData = new FormData ();formData.top = new FormAttachment (0, buttonSpace);formData.left = new FormAttachment (0, buttonSpace);formData.bottom = new FormAttachment (100, -buttonSpace);comp1.setLayoutData (formData);comp1.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));{RowLayout rowLayout = new RowLayout(SWT.VERTICAL);rowLayout.spacing = 8;comp1.setLayout(rowLayout);Label label1 = new Label(comp1,SWT.NONE);label1.setImage(image2);Label label2 = new Label(comp1,SWT.NONE);label2.setImage(image2);Label label3 = new Label(comp1,SWT.NONE);label3.setImage(image2);}formData = new FormData ();formData.top = new FormAttachment (0, buttonSpace);formData.left = new FormAttachment (comp1, 0);formData.bottom = new FormAttachment (100, -buttonSpace);Label label2 = new Label(comp,SWT.SEPARATOR);label2.setLayoutData(formData);}// fill action to right{Composite comp1 = new Composite(comp, SWT.NONE);formData = new FormData ();formData.top = new FormAttachment (0, buttonSpace);formData.right = new FormAttachment (100, -buttonSpace);formData.bottom = new FormAttachment (100, -buttonSpace);comp1.setLayoutData (formData);comp1.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));{RowLayout rowLayout = new RowLayout(SWT.VERTICAL);rowLayout.spacing = 8;comp1.setLayout(rowLayout);Label label1 = new Label(comp1,SWT.NONE);label1.setImage(image2);Label label2 = new Label(comp1,SWT.NONE);label2.setImage(image2);Label label3 = new Label(comp1,SWT.NONE);label3.setImage(image2);}formData = new FormData ();formData.top = new FormAttachment (0, buttonSpace);formData.right = new FormAttachment (comp1, 0);formData.bottom = new FormAttachment (100, -buttonSpace);Label label2 = new Label(comp,SWT.SEPARATOR);label2.setLayoutData(formData);}Button button = new Button(comp, SWT.PUSH);button.setImage(display.getSystemImage(SWT.ICON_QUESTION));button.setText("Some Action");formData = new FormData ();formData.top = new FormAttachment (0, 0);formData.left = new FormAttachment (0, 0);formData.right = new FormAttachment (100, 0);formData.bottom = new FormAttachment (100, 0);button.setLayoutData (formData);/* ******************************** */new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));;new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));;new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));;new Composite(shell, SWT.BORDER).setLayoutData(new GridData(GridData.FILL_BOTH));;shell.setSize(800, 560);shell.open();while (!shell.isDisposed ()) {if (!display.readAndDispatch ()) display.sleep ();}image2.dispose();color.dispose();display.dispose ();}}

?

效果图:


SWT 中Button跟Label重叠放置


?

?

读书人网 >编程

热点推荐