Sponsors


Blog powered by TypePad

« The Second Running | Main | Why Ruby? »

August 08, 2006

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:

Table_col_hdr_missing_2












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:

Table_col_hdr_showing

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/277049/5623603

Listed below are links to weblogs that reference Showing SWT TableColumn Text:

Comments

Post a comment

If you have a TypeKey or TypePad account, please Sign In