Flex TextArea 向下滚动

发布于 2024-12-02 13:17:30 字数 613 浏览 1 评论 0原文

我有一个 TextArea 显示所选聊天室中的对话。对于 valueCommit 事件,我使用: verticalScrollPosition = maxVerticalScrollPosition; 并且它可以很好地将文本滚动到底部。然而,在一种情况下,它不能按预期工作。文本很少,所以 TextArea 没有滚动条,然后我放了很多文本,就需要滚动条。文本几乎滚动到底部(仍有几行需要向下滚动)。我很确定它会得到 maxVerticalScrollPosition ,就好像没有滚动条一样。所以问题是我如何等待更新 VerticalScrollPosition 相对于 TextArea 的新大小(现在带有滚动条)。我尝试调用 validateSize 和其他以“validate”开头的方法,但不幸的是没有运气。我还尝试了将插入符号放在文本末尾的老技巧。因此,在获取 maxVerticalScrollPosition 时,TextArea 的 滚动条会产生影响,并且我需要在所有测量完成后更新 verticalScrollPosition

我忘了提及。我使用 htmlText

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 makes a difference when getting maxVerticalScrollPosition and I need to update verticalScrollPosition once all measurements are done.

I forgot to mention. I use htmlText.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

a√萤火虫的光℡ 2024-12-09 13:17:30

在您接受的答案的评论中,您提到了一个更优雅的解决方案。是的,计时器可能不是最好的选择——如果从舞台上删除组件,则需要清理事件监听器;如果您多次使用该组件,则会有另一个计时器实例; 我

如果您没有很多提交后属性操作,最快的解决方案是稍后调用 text 或 htmlText 的 setter

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

    callLater( scrollToEndAfterTextCommitted );
}

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

希望有所帮助。
祝你好运!

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!

夜未央樱花落 2024-12-09 13:17:30

假设再次添加其他文本后问题得到解决,您可能可以通过使用 Timer 或调用 setTimeout 并设置 verticalScrollPosition = maxVerticalScrollPosition< /code> 稍后调用,看看是否可以解决问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文