隐藏SWT控件

时间:2017-12-12 04:13:16

标签: eclipse-rcp

我们如何隐藏SWT控件? 我知道可以使用控件类的setVisible()方法。但缺点是,隐藏的小部件不会被释放,也不能被其他小部件使用。

还有其他方法可以采用吗?

1 个答案:

答案 0 :(得分:3)

您可以使用布局数据。对于GridLayout,您可以使用排除特定小部件来淹没在画布上。

Composite comp = new Composite(shell, SWT.NONE);  
comp.setLayout(new GridLayout(4, false));  
Label hidenLabel = new Label (comp, SWT.NONE);  
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);  
hidenLabel.setGridData(gridData );  
//hide the button  
gridData .exclude = true;  
comp.pack();