Add icon button beside tree item in eclipse tree

蓝咒 提交于 2019-12-13 02:35:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!