0

viewer.getControl().addListener(SWT.MeasureItem, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TreeItem item = (TreeItem)event.item;
                String text = getText(item, event.index);
                Point size = event.gc.textExtent(text);
                event.width = size.x;
                event.height = Math.max(event.height, size.y);
            }
        });

In the above code snippet the listener is added but it is not coming to handleEvent method at all.

greg-449
  • 109,219
  • 232
  • 102
  • 145
user1223879
  • 123
  • 3
  • 13
  • All rows of a tree are always the same height so you can't have a different number of lines in different rows if that is what you are asking. – greg-449 Apr 20 '15 at 16:10
  • If so then how is it possible for a simple Tree? Please check the [link](http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet227.java) – user1223879 Apr 20 '15 at 16:13
  • You can have multiple lines but all the rows will have the same number of lines. – greg-449 Apr 20 '15 at 16:14
  • That is fine for me but in the snippet I pasted above the execution never comes to handleEvent() method. – user1223879 Apr 20 '15 at 16:16

1 Answers1

1

For TreeViewer do not try to add Listeners as that will interfere with the operation of the viewer.

To draw the lines yourself use a Label Provider which extends OwnerDrawLabelProvider and implement the measure, erase and paint methods.

greg-449
  • 109,219
  • 232
  • 102
  • 145