开发者

Flex TextArea scroll down

开发者 https://www.devze.com 2023-04-01 03:43 出处:网络
I have a TextArea that shows the conversation from selected chat room. For valueCommit event I use: verticalScrollPosition = maxVerticalScrollPosition; And it works fine scrolling text to the bottom.

I have a TextArea that shows the conversation from selected chat room. For valueCommit event I use: verticalScrollPosition = maxVerticalScrollPosition; And it works fine scrolling text to the bottom. However in one case it doesn't work as expected. There's verylittle text, so TextArea has no scrollbar and then I put a lot of text and a scrollbar is necessary. The text is scrolled almost to the bottom (still a few lines need to be scrolled down). I am pretty sure it gets maxVerticalScrollPosition as if there was no scrollbar. So the question is how can I wait with updating verticalScrollPosition with respect to TextArea's new size (that is now with a scrollbar). I tried calling validateSize and other methods that start with 'validate' but unfortunately with no luck. I also tried the old trick of putting caret at the end of text. So the TextArea's scrollbar 开发者_如何学JAVAmakes a difference when getting maxVerticalScrollPosition and I need to update verticalScrollPosition once all measurements are done.

I forgot to mention. I use htmlText.


In the comments of the answer you accepted you mentioned a more elegant solution. Yeah, a timer probably isn't the best option -- you have eventListener cleanup if you remove the component from the stage; if you use the component more than once, you have another timer instance; etc., etc.

If you don't have a lot of post-commit-property actions, the quickest solution would be a call later on the setter of text or htmlText

override public function set text(value:String):void
{
    super.text = value;

    callLater( scrollToEndAfterTextCommitted );
}

protected function scrollToEndAfterTextCommitted():void
{
    this.verticalScrollPosition = this.maxVerticalScrollPosition;
}

I hope that helps. Best of luck!


Assuming the issue is fixed after you add additional text again, you could probably get by using a Timer, or a call to setTimeout and have the verticalScrollPosition = maxVerticalScrollPosition called a fraction of a second later and see if that fixes it.

0

精彩评论

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