Take the 2-minute tour ×

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 wide.

Any ideas on how to do this?

share|improve this question
Is using a Flex4 RichEditableText an option? –  Marty Pitt Jun 30 '10 at 15:26
Wouldn't this be an operating system specific thing? Or possibly font related. I wouldn't expect any Flash APIs allow you to change this. –  JeffryHouser Jun 30 '10 at 15:32
@Marty - Thanks for the suggestion. Unfortunately I'm on a tight schedule and thus tied to Flex 3. @www.Flextras.com - I tried creating a custom font glyph that was 5 characters wide, but the text area didn't seem to like that. I'm hoping to achieve a work around in AS. –  Bryan Jun 30 '10 at 15:43

2 Answers 2

What about something like this?

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

  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.

share|improve this answer

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;

share|improve this answer

Your Answer


