Setting truncateToFit on Label in Tree
I have a tree component sitting in a divided box. I want to display '...' on the node labels if the divided box is resized. I have a custom itemrenderer and have been looking at the labelFunction property as well as trying various approaches in the custom itemrenderer. Not having any joy. Any pointers would be apprecia开发者_开发百科ted.
heres some sample code fo how I set it up...
I define a tree...
<mx:Tree
id="tree"
dataProvider="myData"
labelFunction="treeNodeLabel"
width="100%" height="100%"
click="handleClick(event)"
mouseMove="handleMouseMove(event)"
itemRollOver="handleItemOver(event)"
itemRollOut="handleItemOut(event)"
doubleClickEnabled="true"
doubleClick="handleDoubleClick(event)"
iconFunction="customIcon"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
dragOver="onDragOver(event)"
dragStart="onDragStart(event)"
dataDescriptor="{new DiagramTreeDataDescriptor()}"
itemRenderer="myCustomeRenderer"
borderStyle="none"
>
The Custom Renderer is an Actionscript class that extends TreeItemRenderer...
public class myCustomRenderer extends TreeItemRenderer {
public function myCustomRenderer() {
super();
}
/**
* Create child objects of the component.
*/
override protected function createChildren():void {
super.createChildren();
createIcon();
addListeners();
addChild(Icon1);
addChild(Icon2);
}
private function createIcon() : void {
...
}
private function addListeners() : void {
...
}
private function Icon1Click(event: MouseEvent):void {
...
}
private function Icon2Click(event: MouseEvent): void {
...
}
private function onLabelMouseOver(event : MouseEvent):void {
...
}
private function onLabelMouseOut(event : MouseEvent):void {
...
}
private function getDescription(node : XML):String {
...
}
override protected function updateDisplayList(...) {
...
}
override public function set listData(value:BaseListData):void {
...
}
}
You can set
labelDisplay.maxDisplayedLines = 1
Also, to be able to truncate, the labelDisplay must have a specified width. I don't know what's the default behavior inside a renderer. You can try to first set a width on the renderer itself (absolute or in percentage). If it does not work, set it on the labelDisplay.
精彩评论