Hi,
How do I reset the JScrollPane to the topmost when I have added a very
long text into the JTextPane with JScrollPane in it?
Roland - 18 Mar 2005 07:31 GMT
> Hi,
>
> How do I reset the JScrollPane to the topmost when I have added a very
> long text into the JTextPane with JScrollPane in it?
yourJTextPane.setCaretPosition(0);

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
Thomas Weidenfeller - 18 Mar 2005 09:01 GMT
> How do I reset the JScrollPane to the topmost when I have added a very
> long text into the JTextPane with JScrollPane in it?
setCaretPosition()

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Chris Smith - 18 Mar 2005 15:55 GMT
> How do I reset the JScrollPane to the topmost when I have added a very
> long text into the JTextPane with JScrollPane in it?
If you don't want to change the caret position as others have suggested,
then try calling scrollRectToVisible on the JTextPane. In a more
general case, if you wish to ensure that some specific character
position ("pos") is visible in a JTextComponent of any sort, then you
can say:
JTextPane textPane = ...;
int pos = ...;
textPane.scrollRectToVisible(textPane.modelToView(pos));
If you use 0 for pos, this will cause the text component to scroll to
the top.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation