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
Andrew Thompson - 29 Apr 2004 16:15 GMT
> I have something like this:
O-Oh! How about something like this?
<http://www.physci.org/codes/sscce.jsp>
But as an aside, I came away from your
description wonderring..
Is it always the _second_ method called,
or do you always call them in the same order?
[ It could be, if you call the second method
_1st_, you might find it just plain and simple
does not work, even without the added complication
of being called second. ]

Signature
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
LongBow - 29 Apr 2004 16:24 GMT
It is actually a chat program and the two insert-functions are called in
different times when I send a msg or when a msg is received
> > I have something like this:
>
[quoted text clipped - 10 lines]
> does not work, even without the added complication
> of being called second. ]
LongBow - 29 Apr 2004 16:28 GMT
and yes, it is always when the insert-function with styleHe is used that the
scrolling stops, no matter if it is called first or after.
> It is actually a chat program and the two insert-functions are called in
> different times when I send a msg or when a msg is received
[quoted text clipped - 13 lines]
> > does not work, even without the added complication
> > of being called second. ]
LongBow - 30 Apr 2004 08:58 GMT
Solved it now. Thanks anyway!
> and yes, it is always when the insert-function with styleHe is used that the
> scrolling stops, no matter if it is called first or after.
[quoted text clipped - 16 lines]
> > > does not work, even without the added complication
> > > of being called second. ]