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

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

最佳答案

您可以使用布局数据。在使用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();

09-27 03:37