I extended JTextPane, added this method and call it when I add text to the pane
public void appendText(String text) {
try {
Document doc = getDocument();
//Move the insertion point to the end
setCaretPosition(doc.getLength());
//insert text
replaceSelection(text);
//Convert the new end location
//to view co-ordinates
Rectangle r = modelToView(doc.getLength());
//Finally, scroll so that the new text is visible
if(r != null)
scrollRectToVisible(r);
} catch (BadLocationException e) {
System.out.println("Failed to append text: " + e);
}
}
(Embedded "Richard O. Hammer" <[EMAIL PROTECTED]>@trijug.org
image moved 09/12/2003 02:39 PM
to file:
pic17432.pcx)
Please respond to "Research Triangle Java User's Group mailing list."
<[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
To: Java Users Group <[EMAIL PROTECTED]>
cc:
Subject: [Juglist] always scrolling to the bottom
Security Level:? Internal
I have a stream of text going to a console (a JTextArea in a
JScrollPane in a JFrame). I want it to scroll down automatically so
that I can always see the most recently written text at the bottom.
How do I do that?
Thanks.
Rich Hammer
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org
pic17432.pcx
Description: Binary data
_______________________________________________ Juglist mailing list [EMAIL PROTECTED] http://trijug.org/mailman/listinfo/juglist_trijug.org
