AS3 DataGrid组件设置与使用

本文介绍如何在Flash CS3中使用DataGrid组件并定制其样式,包括设置不同列的字体大小、颜色及对齐方式。通过创建自定义CellRenderer类实现对特定列的样式调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

flash cs3中使用DataGrid组件时, 要改变单元格里的字体大小颜色真是麻烦!
以下是方法:

var list:DataGrid = new DataGrid();
//其他的数据,宽高什么的等属性自己设去吧;

////////TextFormat////////
var tf1:TextFormat = new TextFormat();
tf1.size = 12;
tf1.color = 0x000000;
//其他的属性自己调;

var tf2:TextFormat = new TextFormat();
tf2.size = 13;
tf2.color = 0xff0000;
tf2.bold = true;
//其他的属性自己调;
////////TextFormat////////

//下面是应用:
list.setRendererStyle("textFormat", tf1);//这是设置表头上的单元格文字格式;
list.setStyle("headerTextFormat", tf2);//这是设置表内单元格上的文字样式;

以前是表格内所有单元格沿用一种样式, 但有时候希望某一列的样式要不一样. 比方说我要第一列的内容居中,其他的还是上面那种样式呢?
那就看下面:

新建一个类:

package {
    import fl.controls.listClasses.CellRenderer;
    import fl.controls.listClasses.ICellRenderer;
    import flash.text.TextFormat;
    
    public class CellStyle1 extends CellRenderer implements ICellRenderer {

        public function CellStyle1():void {
            super();
        }

        override protected  function drawBackground():void {
            var format:TextFormat=new TextFormat  ;

            format.color=0x000000;
            format.size=12;
            format.align = "center";
            //其他属性自己设;
            setStyle("textFormat",format);
            super.drawBackground();
        }
    }
}

应用:

//将第一列所有单元格的样式设置为CellStyle1里的format所具有的样式;单元格表头不在范围内;
list.getColumnAt(0).cellRenderer = CellStyle1;

//当然也可以一次性设置同一种样式;
list.setStyle("cellRenderer",CellStyle1);
(如果CellStyle1里的format的样式效果和tf1相同的话,那么上面效果等同于:
list.setRendererStyle("textFormat", tf1);//这是设置表头上的单元格文字格式;

如果每列都要不同的效果可能就要多个CellStye1类吧!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值