Flex中如何在TextArea中使用Tab Stops的例子
By Minidxer | July 4, 2009
接下来的例子演示了Flex中如何通过在tabStops属性上设置TextFormat对象,defaultTextFormat属性以及setTextFormat()函数,在TextArea中使用Tab Stops。
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application name="TextArea_tabStops_test"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- private function init1():void {
- var tf:TextFormat = new TextFormat();
- tf.tabStops = [100, 200, 300, 400];
- textArea1.mx_internal::getTextField().setTextFormat(tf);
- }
- private function init3():void {
- textArea3.htmlText = "<TEXTFORMAT TABSTOPS='100,200,300,400'><P>The quick<TAB/>brown fox<TAB/>jumps over<TAB/>the lazy<TAB/>dog.</P><P>The<TAB/>quick brown<TAB/>fox jumps<TAB/>over the<TAB/>lazy dog.</P></TEXTFORMAT>";
- }
- private function init4():void {
- var tf:TextFormat = new TextFormat();
- tf.tabStops = [100, 200, 300, 400];
- textArea4.mx_internal::getTextField().defaultTextFormat = tf;
- textArea4.text = "The quick\tbrown fox\tjumps over\tthe lazy\tdog.\nThe\tquick brown\tfox jumps\tover the\tlazy dog.";
- textArea4.validateNow();
- trace(textArea4.htmlText);
- }
- ]]>
- </mx:Script>
- <mx:TextArea id="textArea1"
- condenseWhite="true"
- width="500"
- creationComplete="init1();">
- <mx:htmlText>
- <![CDATA[
- <p>The quick<tab/>brown fox<tab/>jumps over<tab/>the lazy<tab/>dog.</p><p>The<tab/>quick brown<tab/>fox jumps<tab/>over the<tab/>lazy dog.</p>
- ]]>
- </mx:htmlText>
- </mx:TextArea>
- <mx:TextArea id="textArea2"
- condenseWhite="true"
- width="500">
- <mx:htmlText>
- <![CDATA[
- <TEXTFORMAT TABSTOPS="100,200,300,400"><P>The quick<TAB/>brown fox<TAB/>jumps over<TAB/>the lazy<TAB/>dog.</P><P>The<TAB/>quick brown<TAB/>fox jumps<TAB/>over the<TAB/>lazy dog.</P></TEXTFORMAT>
- ]]>
- </mx:htmlText>
- </mx:TextArea>
- <mx:TextArea id="textArea3"
- condenseWhite="true"
- width="500"
- initialize="init3();" />
- <mx:TextArea id="textArea4"
- width="500"
- initialize="init4();" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
TextArea |
No Comments » |
577 views
Tags: defaultTextFormat, getTextField, mx internal, setTextFormat(), tabStops, TextArea, TextFormat