隐藏 SWT 控件

Hiding SWT Controls

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

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

您可以使用布局数据。在 GridLayout 的情况下,您可以使用排除特定小部件被淹没 canvas。

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();