stacklayout 实例
swt 堆栈式布局 StackLayout 2009-08-27 09:34package swt.demo;import org.eclipse.swt.SWT;public class swtStackLayout {/*** 堆栈式布局*/public static void main(String[] args) {Display display = new Display();final Shell shell = new Shell(display);GridLayout gl = new GridLayout();gl.numColumns = 3;shell.setLayout(gl);// 窗体使用网格布局shell.setText("StackLayout 堆栈式布局 (在某区域内隐藏控件,选择需要显示的控件)");final Composite parent = new Composite(shell, SWT.NONE);parent.setLayoutData(new GridData(GridData.FILL_BOTH));GridData gd = new GridData(GridData.FILL_BOTH);gd.horizontalSpan = 3;parent.setLayoutData( gd );final StackLayout sl = new StackLayout();parent.setLayout(sl);final Button bt1 = new Button(parent, SWT.PUSH);bt1.setText("普通按钮");final Button bt2 = new Button(parent, SWT.CHECK);bt2.setText("多选按钮");final Button bt3 = new Button(parent, SWT.RADIO);bt3.setText("单选按钮");sl.topControl = bt1;Button sbt1 = new Button(shell, SWT.PUSH);sbt1.setText("显示普通按钮");sbt1.addListener(SWT.Selection, new Listener(){@Overridepublic void handleEvent(Event event) {sl.topControl = bt1;parent.layout();}});Button sbt2 = new Button(shell, SWT.PUSH);sbt2.setText("显示多选按钮");sbt2.addListener(SWT.Selection, new Listener(){@Overridepublic void handleEvent(Event event) {sl.topControl = bt2;parent.layout();}});Button sbt3 = new Button(shell, SWT.PUSH);sbt3.setText("显示单选按钮");sbt3.addListener(SWT.Selection, new Listener(){@Overridepublic void handleEvent(Event event) {sl.topControl = bt3;parent.layout();}});shell.setLocation(100, 100);shell.setSize(500, 350);shell.open();while (!shell.isDisposed()) {if (!display.readAndDispatch())display.sleep();}display.dispose();}}?