title: How to auto scroll down JTextArea after append?
body: <p>I've created a JFrame, with a JTextArea. I would like to scroll down the textarea automatically, after each append. How should I manage it?</p>
  
  <p>I've tried <code>log.setCaretPosition(log.getDocument().getLength());</code>, but nothing changed.</p>
  
  <pre><code>package scrollit;
  
  import java.awt.*;
  import javax.swing.*;
  import static javax.swing.JFrame.EXIT_ON_CLOSE;
  
  public class ScrollIt extends JFrame {    
  
      public static void main(String[] args) {            
          ScrollIt sc = new ScrollIt();            
      }
  
      public ScrollIt() {
          super();            
          JTextArea log = new JTextArea();
          log.setPreferredSize(new Dimension(50,50));
          setDefaultCloseOperation(EXIT_ON_CLOSE);            
          add(log);            
          pack();
          setVisible(true);
  
          log.append("a\n");
          log.append("b\n");
          log.append("c\n");
          log.append("d\n");
          log.append("e\n");
          log.append("f\n");
      }
  }
  </code></pre>