views:

265

answers:

2

I am trying to implement a JScrollPane with a JTextArea. The JTextArea is being appended to, and I want the JScrollPane to keep scrolling down as more text is added. How can this be achieved?

A: 

I found the answer here: http://stackoverflow.com/questions/2132444/jscrollpane-and-jlist-auto-scroll

scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {  
        public void adjustmentValueChanged(AdjustmentEvent e) {  
            e.getAdjustable().setValue(e.getAdjustable().getMaximum());  
        }
    });
Krigath
Your "solution" is actually the problem of the linked-to question: if you manually try to move the vertical scroll handle, this code will scroll to the bottom again!
jackrabbit
+3  A: 

For (what I think is) a simpler answer check out: Text Area Scrolling.

camickr
+1 The `setUpdatePolicy()` API explains _so_ much. I've updated my answer to the cited question accordingly.
trashgod
Yes, the API keeps changing its hard to keep up with changes all the time.
camickr