开发者

How to change width of TAB character in a Flex TextArea?

Is it possible to change the width of an insert TAB character in a Flex TextArea?

I'm capturing FocusEvent.KEY_FOCUS_CHANGE events and manually inserting a "\t" into a text area styled with an embedded monospace font. By default, the TABs are being displayed two and a half monospace characters wide... I need them to display five monospace characters 开发者_C百科wide.

Any ideas on how to do this?


What about something like this?

<mx:Canvas>
    <mx:Script>
        [Bindable]
        public var myText:String;
    </mx:Script>
    <mx:TextArea id="textArea" text="{TabUtil.expand(myText)}" valueCommit="myText = TabUtil.contract(myText))" />
 </mx:Canvas>



  public class TabUtil
  {
       public static const SPACE:String = "     "; // Five spaces;
       public static function expand(text:String):String
       {
            return text.replace("\t",SPACE);
       }
       public static function contract(text:String):String
       {
            return text.replace(SPACE,"\t");
        }
   }

I forget the params of replace, but I think it may take a RegEx, in which case you'd need to tweak the above. But it should work.


The tabStops property of textFormat is what you are looking for. You can set the pixel values of where you want each tab to be placed.

var tf:TextFormat = new TextFormat(); tf.tabStops = [100, 200, 300, 400]; myTextArea.mx_internal::getTextField().defaultTextFormat = tf;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜