ScrollPane scrolls to the bottom

I have a TextArea in my Java application and I am adding a lot of lines of text. I need the ScrollPane to scroll to the last add (at the bottom of TextArea). How can i do this?

+3
source share
5 answers

You can do this by moving the carriage position to the bottom, this will automatically scroll through the TextArea:

textArea.setCaretPosition(textArea.getDocument().getLength());
+9
source

Scrolling in a text area explains how scrolling works in a bit more detail and provides an alternative solution that could be simpler.

+4
source

Amjad Masad , .

: JTextArea (AKA ), , ( ). - . , () Ctrl + , .

+2

You should check if you are on EDT when you call append. If you go beyond the EDT when calling append, JTextArea does not scroll to the last line added (see My post with an example run: scrolling JScrollPane with the last line added ).

0
source

Source: https://habr.com/ru/post/1782253/


All Articles