2013-11-27 35 views
0

我用TableViewer創建了一個網格。如何使用表格在網格中顯示消息?

在某些情況下,我想隱藏TableViewer並顯示消息。

這是我如何創建的TableViewer:

gridLayout = new GridLayout(); 
Table table = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL |  SWT.FULL_SELECTION | SWT.BORDER) 
table.setLayoutData(gridLayout) 

我知道如何隱藏表 - table.setVisible(假)。問題在哪裏設置消息?我沒有爲此創建一個文本框(SWT)。

我是否需要創建文本框(SWT)並將false設置爲可見(默認情況下),並且僅當我想要顯示消息以將其顯示爲visible = true時?

+0

是的;)這是一種方法,你可以做到這一點 – Mirco

回答

0

就像你說的那樣。這裏有一些代碼更多一些。

// The parents layout of message and table viewer 
GridLayout gridLayout = new GridLayout(2, false); 
parent.setLayout(gridLayout); 

// The message widget 
Text message = new Text(parent, SWT.NONE); 
message.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL 
GridData.HORIZONTAL_ALIGN_FILL)); 

// The table viewer 
TableViewer viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL |  SWT.FULL_SELECTION | SWT.BORDER); 
Table table = viewer.getTable(); 

// Layout for table 
GridData gridData = new GridData(); 
// fill in your grid data setup here 
// EX: gridData.verticalAlignemnt = GridData.FILL; 
// end fill 
viewer.getControl().setLayoutData(gridData); 
相關問題