Reputation: 155
I am trying to add multiple icons for the swt tree by appending more images into one long image and then adding it for each tree node. The problem is that the dashed line is elongated more and more as the width of the image increases(see the picture). I tried to add paint listeners but I am having some repainting problem, so the paint listeners don't work for me. If anyone has any suggestions, please help.
switch (event.type) {
case SWT.MeasureItem: {
final Object value = ((TreeItem) event.item).getData();
final BrowserNode node = getBrowserNode(value);
Image image = getCombinedImage(node.getImage1(),node.getImage2(),node.getImage3(),node.getImage4());
Rectangle rect = image.getBounds();
event.width += rect.width;// rect.width*2;
event.height = Math.max(event.height, rect.height + 2);
break;
}
case SWT.PaintItem: {
BrowserNode node = getBrowserNode(((TreeItem) event.item).getData());
Image image = getCombinedImage(node.getImage1(),node.getImage2(),node.getImage3(),node.getImage4());
Rectangle rect = image.getBounds();
int offset = Math.max(0, (event.height - rect.height) / 2);
event.gc.copyArea(event.x, event.y, event.width, event.height, event.x + image.getImageData().width-30, event.y + offset, false);
event.gc.fillRectangle(event.x, event.y, image.getImageData().width, event.height);
event.gc.drawImage(image, event.x, event.y + offset);
break;
}
}
Upvotes: 2
Views: 631
Reputation: 21025
The excessive indentation of tree nodes is specific to Windows, other platforms do not behave this way.
This issue is discussed in this bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=185004
The suggested workaround is to draw the tree items yourself.
Upvotes: 2