Thursday, March 10, 2011

Using hand cursors in the flex tree

Normally getting hand cursors to show on flex components involves setting useHandCursor="true", buttonMode="true", and mouseChildren="false". Sadly this blows up the tree as you aren't able to select anything.  The way around this is to set  useHandCursor="true" buttonMode="true" on your <mx:Tree/> component and then set super.mouseChildren = false in an itemRenderer like so:

package somepackage
{
import mx.controls.treeClasses.TreeItemRenderer;
import mx.controls.treeClasses.TreeListData;

public class ReportsTreeItemRenderer extends TreeItemRenderer
{
public function ReportsTreeItemRenderer()
{
super();
}

override public function set data(value:Object):void
{
super.data = value;

if( super.data )
{
super.mouseChildren = false;
if( TreeListData(listData).depth == 1 )
setStyle('fontWeight', 'bold');
else {
setStyle('fontWeight', 'normal');
}
}
}
}
}

2 comments:

  1. Muito obrigado !!
    salvou minha vida !

    ReplyDelete
  2. Nathan5x4:43 AM

    You're a life saver man. :)

    Thanks a ton.

    ReplyDelete