如何控制JavaFX TextArea自动滚动? [英] How to control the JavaFX TextArea auto scroll?

查看:643
本文介绍了如何控制JavaFX TextArea自动滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我每隔2分钟将文本附加到 TextArea 。当我将新行追加到 TextArea 时,自动滚动会自动停止。但我想保留滚动按钮,我保持滚动按钮。如何在JavaFX中执行此操作。

In my application I am appending the text to TextArea every 2 minutes. When ever I append new line to TextArea the auto scroll automatically going to down. But I want to stay the scroll where i am keep the scroll button. How to do it in JavaFX.

logTextArea.appendText("Here i am appending text to text area"+"\n");
logTextArea.setScrollTop(Double.MIN_VALUE);

我试过这个但是自动滚动下去,但我需要保持我的滚动选择位置我不要我想自动失败。

I tried this but scroll automatically going to down , but I need to keep my scroll chosen position I don't want to go automatically down.

我该怎么做?

推荐答案

最简单的方法是记住插入符号的位置,并在它被 appendText setText

The most straightforward way is to remember the position of the caret and restore it after it gets moved by appendText or setText.

以下是如何做到这一点:

Here's how you can do it:

int caretPosition = area.caretPositionProperty().get();
area.appendText("Here i am appending text to text area"+"\n");
area.positionCaret(caretPosition);

这篇关于如何控制JavaFX TextArea自动滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆