2015-06-14 66 views
0

有人能幫助我嗎? 我在SWT中有一個表格,我只想顯示一些表格項目,但表格只顯示一個項目,而其他項目用垂直滾動顯示。我想顯示一切,不滾動。我嘗試使用選項SWT_NO_SCROLL,但不起作用。我有一個方法創建表和其他填充它創建一個新的表項,他們工作良好,問題是隻顯示第一個項目,其他滾動。SWT - 顯示多個表項

我的代碼是:

private void createTable(Composite parent){ 

    table = new Table (parent, SWT.BORDER); 

    TableColumn tcFile = new TableColumn(table, SWT.LEFT); 
    TableColumn tcStatus = new TableColumn(table, SWT.LEFT); 

    tcFile.setText("File"); 
    tcStatus.setText("Status"); 

    tcFile.setWidth(500); 
    tcStatus.setWidth(500); 

    table.setVisible(true); 
    table.setHeaderVisible(true); 
} 

private void populateTable(String file, String status){ 
    TableItem item = new TableItem(table, SWT.LEFT); 
    item.setText(new String[] { file, status}); 

} 


Composite top = new Composite(parent, SWT.WRAP); 
GridLayout layout = new GridLayout(); 
layout.marginHeight = -5; 
layout.marginWidth = 0; 
top.setLayout(layout); 

Composite banner = new Composite(top, SWT.WRAP); 

banner.setLayoutData(new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_BEGINNING, false, false)); 
layout = new GridLayout(); 
layout.marginHeight = 0; 
layout.marginWidth = 10; 
layout.numColumns = 5; 
banner.setLayout(layout); 

createTable(top); 
+0

你是如何設置垂直表的大小?你在使用Layout還是setBounds? –

回答

1

您還沒有指定爲Table任何佈局的數據,你可以試試:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); 
table.setLayoutData(data); 

如果你沒有任何其他事物設置對話框/窗口大小,你可能需要指定一個表格高度提示:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); 
data.heightHint = 200; // Vertical size for table 
table.setLayoutData(data); 
+0

Greg!你是個天才!我沒有意識到那個代碼丟失了。我一般都是SWT和Java的新手,所以我有太多需要學習的東西。非常感謝你!!!!! –

+0

對不起格雷格,我看過你在RCP/SWT應用程序方面有很多經驗,你知道創建一個帶有3個透視快捷鍵的工具欄是非常困難的嗎?當我打開應用程序時可以切換到這個快捷方式。因爲我無法找到關於SWT的許多信息。 –

+0

SWT只是低級別的控件。透視圖是Eclipse RCP功能 –