2014-02-07 52 views
0

我創建了一個包含兩個對象的複合(SWT):標籤和文本。如何在SWT中隱藏組合?

在某些情況下,我不希望看到這些小部件。當我按下一個按鈕時,我想隱藏組合。

我必須選擇隱藏複合材料,所以它不會按住屏幕上的地方嗎? (我不希望看到的空行,我旁邊有其他對象)

我可怎麼辦呢?

Composite comp = new Composite(shell, SWT.NONE); 
    layout = new GridLayout(); 
    layout.numColumns = 2; 

Label label = new Label(comp , SWT.BORDER); 
label.setText("This is a label:"); 
label.setToolTipText("This is the tooltip of this label"); 

Text text = new Text(comp , SWT.NONE); 
text.setText("This is the text in the text widget"); 
text.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); 
text.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 

回答

0

可以使用dispose()方法來刪除Composite。 但是,如果您想再次顯示,則必須再次創建Composite

編輯:

好吧,或者只是使用Baz發佈的解決方案。 這是一個更好的辦法...

+0

隱藏是非常不同的模式比配置,特別是對於那些可能有其他的孩子,等等。這不應該被推薦的更復雜的部件。 – Krease