its very easy

public void addText(JTextArea jt,String text){

    jt.append("\n"+text);
    jt.setCaretPosition(jt.getText().length());

}
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 12, 2003 8:55 PM
Subject: Re: [Juglist] always scrolling to the bottom


>
> 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
>
>
>


----------------------------------------------------------------------------
----


> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>



_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to