stacklayout 实例

swt 堆栈式布局 StackLayout 
2009-08-27 09:34
package 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(){
@Override
public void handleEvent(Event event) {
sl.topControl = bt1;
parent.layout();
}

});
Button sbt2 = new Button(shell, SWT.PUSH);
sbt2.setText("显示多选按钮");
sbt2.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event event) {
sl.topControl = bt2;
parent.layout();
}

});
Button sbt3 = new Button(shell, SWT.PUSH);
sbt3.setText("显示单选按钮");
sbt3.addListener(SWT.Selection, new Listener(){
@Override
public 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();

}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值