您的位置:首页 > 其它

SWT:StackLayout(堆栈式布局)

2013-04-01 21:07 836 查看
shell.setLayout(new GridLayout());

//创建放置文本框的面板

final Composite parent = new Composite(shell, SWT.NONE);

//设置面板的布局数据

parent.setLayoutData(new GridData(GridData.FILL_BOTH));

//创建堆栈式布局

final StackLayout layout = new StackLayout();

//将堆栈式布局应用于面板

parent.setLayout(layout);

//创建10个文本框

final Text[] textArray = new Text[10];

for (int i = 0; i < 10; i++)

{

textArray[i] = new Text(parent, SWT.MULTI);

textArray[i].setText("这是第 " + i + "个文本框");

}



//设置堆栈中当前显示的控件

layout.topControl = textArray[0];



Button b = new Button(shell, SWT.PUSH);

b.setText("显示下一个文本框");

//保存当前显示的文本框的索引值

final int[] index = new int[1];

//为按钮添加单击事件

b.addListener(SWT.Selection, new Listener(){

public void handleEvent(Event e)

{

//计算出下一个文本框的索引数

index[0] = (index[0] + 1) % 10;



//设置当前显示的控件

layout.topControl = textArray[index[0]];

//重新刷新布局

parent.layout();

}

});



shell.setSize(200, 150);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: