如:假设composite里包含composite1、composite2,composite1上面有一个按钮button1,
实现的效果是:首先composite1适应一个button的大小,button1有个事件,单击时在composite2显示/隐藏,composite2显示时composite1缩小以显示composite2,composite2隐藏时composite1就要自动放大充满整个composite.
实现如下:
把composite1与composite2放在composite中
//composite1
Composite composite1= new Composite(composite, SWT.NONE);
final GridData gd_compositeOrder = new GridData(SWT.FILL, SWT.FILL, true, true);
composite1.setLayoutData(gd_compositeOrder);
composite1.setLayout(new GridLayout());
//composite2
private void CreateComposite2(){
composite2= new Composite(composite, SWT.NONE);
GridData gd_compositeLeftBottom = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
gd_compositeLeftBottom.heightHint = 249;
composite2.setLayoutData(gd_compositeLeftBottom);
composite2.setLayout(new GridLayout());
}
//button1单击事件
button1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
if(composite2== null){ //显示
CreateComposite2();
composite.layout(true); //刷新布局
}
else{ //隐藏
composite2.dispose();
composite2= null;
composite.layout(true);
}
}
});
或
button1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
((GridData)composite2.getLayoutData()).exclude = !((GridData)composite2.getLayoutData()).exclude;
composite.layout(true);
}
}
});
阅读(3856) | 评论(0) | 转发(0) |