Scrollpane and scrolling down

From: LongBow (kejerhag_at_yahoo.com)
Date: 04/29/04


Date: Thu, 29 Apr 2004 17:03:14 +0200

Hi!
I have a problem with scrolling. I have a JScrollPane with a JTextPane
inside it. Adding text to the textpane is done through a StyledDocument.
There are two functions adding text to the doc (with two different styles).
The problem is that I want the scrollpane to automatically scroll down to
the bottom of all text when text is added. It works fine as long as only one
function is adding text, but as soon as the other starts adding the
"auto"-scrolling doesnt work anymore. I have tried a lot methods, but no one
seems to be working. Can anyone tell me how it should be done?

I have something like this:

JTextPane historyPanel = new JTextPane();
JScrollPane jScrollPane1 = new JScrollPane();
StyledDocument doc = historyPanel.getStyledDocument();
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NE
EDED);
jScrollPane1.getViewport().add(historyPanel, null);

And adding is done through

 doc.insertString(doc.getLength(),text,styleMe);

and

doc.insertString(doc.getLength(),text,styleHe);

Thanks in advance!
/ Morgan



Relevant Pages