Flex TextArea 向下滚动
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您接受的答案的评论中,您提到了一个更优雅的解决方案。是的,计时器可能不是最好的选择——如果从舞台上删除组件,则需要清理事件监听器;如果您多次使用该组件,则会有另一个计时器实例; 我
如果您没有很多提交后属性操作,最快的解决方案是稍后调用 text 或 htmlText 的 setter
希望有所帮助。
祝你好运!
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
I hope that helps.
Best of luck!
假设再次添加其他文本后问题得到解决,您可能可以通过使用
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 tosetTimeout
and have theverticalScrollPosition = maxVerticalScrollPosition
called a fraction of a second later and see if that fixes it.