SWT - show multiple table items

430 views Asked by At

Could anybody help me? I have a table in SWT and simply I want to show some table items but the table only shows one item and the others with vertical scroll. I want to show everything, without scrolling. I tried with the option SWT_NO_SCROLL but is not working. I have a method that creates the table and other that populates it creating a new table item, they´re working good, the problem is that only shows the first item and the other are scrolling.

My code is:

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

There are 1 answers

3
greg-449 On BEST ANSWER

You haven't specified any layout data for the Table, try something like:

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

If you don't have anything else that is setting the dialog/window size you may need to specify a table height hint:

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