效果图:
这样的效果,之前我使用Flex4.5 Spark主题的时候,可以直接显示出来。原理很简单,
<s:DataGrid id="myadDG12" x="0" y="0" width="100%" height="100%" dataProvider="{report_disasterInfo}"
horizontalScrollPolicy="on" fontFamily="宋体" fontSize="12"
gridRollOver="myadDG2_itemRollOverHandler(event)"
gridRollOut="myadDG12_gridRollOutHandler(event)"
rollOut="myadDG12_mouseOutHandler(event)">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="address" headerText="地点" width="155" sortable="false"/>
<s:GridColumn dataField="type" headerText="灾害类型" width="80"sortable="false" />
<s:GridColumn dataField="time" headerText="发灾时间" width="80"sortable="false" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
private function myadDG2_itemRollOverHandler(event:GridEvent):void
{
myadDG12.toolTip="";
myadDG12.toolTip = event.itemRenderer.label;
}
就可显示出来了。
后来我成Halo主题后,上面那个方法出能显示出来。可貌似控件不了他显示的字体大小,无奈之下,就换个方法了,自定义。
import mx.managers.ToolTipManager;
public var myTip:ToolTip ;
/** DataGrid重置Tooltip显示事件*/
private function myadDG2_itemRollOverHandler(event:GridEvent):void
{
if(event.itemRenderer.label != "地点" && event.itemRenderer.label != "灾害类型"
&& event.itemRenderer.label != "发灾时间" ){
if(gridrow != event.rowIndex || gridcolumn != event.columnIndex || stoolTip == null){
if((gridrow != event.rowIndex && gridcolumn != event.columnIndex)
|| (gridrow == event.rowIndex && gridcolumn != event.columnIndex)
|| (gridrow != event.rowIndex && gridcolumn == event.columnIndex)){
if(myTip != null)
myTip.visible = false;
}
myTip = ToolTipManager.createToolTip(event.itemRenderer.label,event.stageX,(event.stageY+20)) as ToolTip;
myTip.setStyle("backgroundColor",0xf6f7c2);
myTip.setStyle("fontSize",13);
myTip.width = myTip.width * 1.3;
myTip.height = 28;
stoolTip = "";
}
else{
myTip.x = event.stageX;
myTip.y = event.stageY+20;
}
}else{
//stoolTip = null;
//if(myTip !=null)
//ToolTipManager.destroyToolTip(myTip);
}
gridrow = event.rowIndex;
gridcolumn=event.columnIndex;
}
删除破坏由 createToolTip()
方法创建的指定 ToolTip。
private function myadDG12_gridRollOutHandler(event:GridEvent):void
{
try{
if(myTip !=null)
ToolTipManager.destroyToolTip(myTip);
}catch(e:Error){
}finally{
stoolTip= null;
}
}
private function myadDG12_mouseOutHandler(event:MouseEvent):void
{
try{
if(myTip !=null)
ToolTipManager.destroyToolTip(myTip);
}catch(e:Error){
}finally{
stoolTip= null;
}
}