How to implement a TreeViewer such that root elements have multiple cells but child elements only a single cell?

StackOverflow https://stackoverflow.com/questions/20733648

  •  20-09-2022
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top