How do I get a JScrollPane to automatically scroll to the bottom of a document each time a new text is added to the document?
Created May 4, 2012
Jesper Berglund
When a text is insterted in a JTextPane, the height of the JTextPane will increase, but the visible rect of the scrollpane is constant. To keep the lowest row visible use the scrollRectToVisible() function and specify where the scrollpane shall scroll.
Example:
jTextPane1.insertString( jTextPane1.getDocument().getLength(), intsertString +" ", null); //scroll the text as it gets more and more jTextPane1.scrollRectToVisible( new Rectangle(0,jTextPane1.getHeight()-2,1,1));