tags:

views:

306

answers:

3

I have an mx:TextArea and I want its height to be the same as its content height. There is nothing fancy - just a text area and text that is not editable. I need a simple and reliable way to make the control fit and show all the text without vertical scroll - something like auto resizing. Also my control's text will be set only once and will not change as it will not be editable.

<mx:TextArea id="myTextArea"
             editable="false"
             width="100%"
             verticalScrollPolicy="off" >
   <mx:text>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id lorem 
      quis ante pulvinar auctor at eget risus. Nulla facilisi. Morbi ultricies 
      dignissim lorem, quis suscipit felis ullamcorper et.
   </mx:text>
</mx:TextArea>

There is one more post here on the same topic but it is not relevant to me because the setup there is a lot more complicated as it includes styling and binding.

A: 

I would suggest playing with "wordWrap='true'" in addition to the scroll policy.

phtrivier
No, that's not it. Word wrap will only transfer the text to a new line if it exceeds the width of the container.
Branislav Abadjimarinov
+1  A: 

Is this what you are looking for?

http://www.flexer.info/2009/02/06/auto-resizable-text-area-component/

Brian
The pure Flash equivalent of this is a TextField primitive with myField.autoSize = TextFieldAutoSize.LEFT;
Ender
+1  A: 

Use the textHeight read-only property of the TextArea, and set the height of the TextArea to be TextArea.textHeight + whatever vertical padding the TextArea uses plus the height of the top and bottom borders (examine the TextArea component and figure those out). This process should happen in a handler you add to the change event for the TextArea.

Robusto