title: Auto text scroll for text area (JTextArea) with caret position set to the beginning of the last line
body: <p>I have a simple Java question here. I want to auto text scroll to the beginning of the last line of a text area created using JTextArea. The amount of text per line of the text area is quite longer than the width of the text area.</p>
  
  <p>Here is the code snippet I used to set that up.</p>
  
  <pre><code>JTextArea textArea = new JTextArea();
  DefaultCaret caret = (DefaultCaret)textArea.getCaret();
  caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
  </code></pre>
  
  <p>The problem now is, with the above code, the default behavior is that the caret is auto positioned to the end of the document, as a result, the beginning part of the whole text area gets out of scope. I'd prefer the auto scroll to happen to the beginning of the last line in the document.</p>
  
  <p>To make it clear, here are two screen shots,</p>
  
  <p>What I want is the first one  but what's happening is the second one.</p>
  
  <p><img src="https://i.stack.imgur.com/spx4q.png" alt="What I want is this">
  <img src="https://i.stack.imgur.com/fsSiC.png" alt="What I get is this"></p>