I have a few text areas that are filled with loops of information. Is it possible to make it 'jump' or scroll back to the top automatically after the loop has completed, so that the user sees it from the start and not the end?
Asked
Active
Viewed 4,618 times
2
-
Possible duplicate: http://stackoverflow.com/questions/291115/java-swing-using-jscrollpane-and-having-it-scroll-back-to-top – Alexandre Jan 31 '12 at 13:26
-
Are you referring to an AWT based `TextArea` or a Swing based `JTextArea`? Please be specific. – Andrew Thompson Jan 31 '12 at 13:27
-
1Why are you using AWT components in this millennium? The few people that did use them have largely forgotten how! – Andrew Thompson Jan 31 '12 at 13:52
-
I'm only using the AWT TextArea as I don't like the way Swing displays without a border, all my other components are Swing! – Mark Tickner Jan 31 '12 at 16:20
3 Answers
0
Use setUpdatePolicy with NEVER_UPDATE, and make sure the setUpdatePolicy comes before setting any text to the JTextArea. In my example I initialize a JTextArea without any text and call setUpdatePolicy right after.
JTextArea jTextArea = new JTextArea();
((DefaultCaret)jTextArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

Ilan Granot
- 11
- 2
-2
I have solved this problem by creating a new TextArea which acts as a sort of buffer (and isn't displayed). The loop writes to this area and when completed gets the text from that and sets it to the required TextArea.

Mark Tickner
- 1,023
- 2
- 15
- 26