Showing SWT TableColumn Text
While creating an Eclipse TableView using Eclipse 3.2, oddly, only one of two defined table column titles was showing up. My table should have showed "Type" and "Name" columns but only the "Type" column header text would appear:
I had set some straightforward column properties:
typeColumn = new TableColumn(table, SWT.LEFT, 0);
typeColumn.setText("Type");
typeColumn.setWidth(40);
typeColumn.setResizable(false);
typeColumn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getTableViewer().setSorter(
new Sorter("Type"));
}
});
nameColumn = new TableColumn(table, SWT.LEFT, 1);
nameColumn.setText("Name");
nameColumn.setResizable(true);
nameColumn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getTableViewer().setSorter(new Sorter("Name"));
}
});
But, alas, no "Name" column header. When table contents populated the viewer, the Name column would appear and all was ok. The problem would show when the table was empty. The culprit?
setWidth()
Calling setWidth() triggers a UI update that causes the column title to appear, even without table contents. Now I set the nameColumn width as follows:
nameColumn = new TableColumn(table, SWT.LEFT, 1);
nameColumn.setText("Name");
nameColumn.setWidth(100);
nameColumn.setResizable(true);
// .. etc
And, viola:


Comments