问题
I wonder how to add an icon that acts as a button in the right side of a tree item
the selection of this icon should have different action than selecting the tree item itself.
How can I do that?
Example:
consider this is the main tree
http://www.eclipse.org/articles/Article-TreeViewer/images/main.gif
and I want to add icons to the right side of some tree items' label like
http://store2.up-00.com/June12/8QI59630.gif
just as when I click on the black star icon, I make a different action than selecting the tree item
回答1:
Such facility does not exist in the tree widget, but you can implement this yourself using a technique called owner-draw where you take over the painting of tree items. See OwnerDrawLabelProvider. To respond to clicks you will need to listen to mouse down even and check whether the coordinates match the bounds of your button before invoking your action.
来源:https://stackoverflow.com/questions/11315477/add-icon-button-beside-tree-item-in-eclipse-tree