Reputation: 2405
The following code shows how to create a TreeViewer
with columns.
TreeViewer treeViewer = new TreeViewer(shell, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
trclmnNewColumn.setWidth(100);
trclmnNewColumn.setText("New Column");
TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
TreeColumn trclmnNewColumn_1 = treeViewerColumn_1.getColumn();
trclmnNewColumn_1.setWidth(100);
trclmnNewColumn_1.setText("New Column");
By default, if you expand a root element row, child element rows appear, and just like the root element rows, they are also divided into cells by the columns.
I would like to implement a TreeViewer
such that child elements, unlike root elements, consist of a single cell that spans the width of the TreeViewer
.
How can this be done?
Upvotes: 0
Views: 536
Reputation: 56
There is one code snippet which shows how to span columns
Table snippet: make text span multiple columns
Also agree with Greg's answer, you can use NatTable as alternative to SWT TreeViewer. It also can render tree and more configurable than SWT TreeViewer
Upvotes: 1
Reputation: 111142
This is not possible with the normal TreeViewer
column support.
You could probably do it using an OwnerDrawLabelProvider
where you have to draw the rows.
The Eclipse Nebula project has some additional grid and tree controls which might do what you want.
Upvotes: 1