|
|
automatic scrolling when inserting a new line to JTextPane
Hi,
I always thought that I do have to set the statement
txtPane.setCaretPosition(txtPane.getDocument().getLength());
for scrolling the text to the last inserted row, but the text
is beeing scolled automatically!
New rows are inserted by
document.insertString(document.getLength(), sTxt + sNewLine, attributes);
sNewLine = "\n\n" or "\n"
document = (StyledDocument)JTextPane.this.getStyledDocument();
Any idea how to prevent autoscrolling for this textcomponent?
Thanks in advance,
Thomas
|
|
0
|
|
|
|
Reply
|
th.barth (12)
|
8/19/2004 9:42:53 AM |
|
"Thomas Barth" <th.barth@mail.isis.de> schrieb im Newsbeitrag
news:2ojb0kFbc36jU1@uni-berlin.de...
> Hi,
> I always thought that I do have to set the statement
>
> txtPane.setCaretPosition(txtPane.getDocument().getLength());
>
> for scrolling the text to the last inserted row, but the text
> is beeing scolled automatically!
>
> New rows are inserted by
>
> document.insertString(document.getLength(), sTxt + sNewLine, attributes);
>
>
> sNewLine = "\n\n" or "\n"
>
> document = (StyledDocument)JTextPane.this.getStyledDocument();
>
> Any idea how to prevent autoscrolling for this textcomponent?
such things made most by calling JComponent#scrollRectToVisible(Rectangle
r);
try to override it to do nothing
--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
|
0
|
|
|
|
Reply
|
ak
|
8/19/2004 1:49:41 PM
|
|
Thomas Barth <th.barth@mail.isis.de> wrote:
> txtPane.setCaretPosition(txtPane.getDocument().getLength());
>
> for scrolling the text to the last inserted row, but the text
> is beeing scolled automatically!
>
> New rows are inserted by
>
> document.insertString(document.getLength(), sTxt + sNewLine, attributes);
>
>
> sNewLine = "\n\n" or "\n"
>
> document = (StyledDocument)JTextPane.this.getStyledDocument();
>
> Any idea how to prevent autoscrolling for this textcomponent?
Change its Caret (DefaultCaret.ensureVisibility).
Christian
|
|
0
|
|
|
|
Reply
|
usenet
|
8/19/2004 3:02:12 PM
|
|
>
>
> Change its Caret (DefaultCaret.ensureVisibility).
txtPane.getCaret().setVisible(true);?
It doesn't work. What does the visibility of texpanes caret have to do with the scrolling function?
The text is still scrolled to the the inserted row. For month I have tested inserted lines in a jtextpane
and I always could switch between true or false for scrolling
if (bAutoScroll) {
txtPane.setCaretPosition(txtPane.getDocument().getLength());
}
Thomas
|
|
0
|
|
|
|
Reply
|
Thomas
|
8/19/2004 3:36:24 PM
|
|
Thomas Barth <th.barth@mail.isis.de> wrote:
>
>>
>>
>> Change its Caret (DefaultCaret.ensureVisibility).
^^^^^^
should be "adjust".
> txtPane.getCaret().setVisible(true);?
No.
> It doesn't work. What does the visibility of texpanes caret have to do with the scrolling function?
The automatic scrolling is caused by DefaultCaret.adjustVisibility (which
has nothing to do with set/isVisible).
> The text is still scrolled to the the inserted row. For month I have tested inserted lines in a jtextpane
>
> and I always could switch between true or false for scrolling
>
> if (bAutoScroll) {
>
> txtPane.setCaretPosition(txtPane.getDocument().getLength());
>
> }
That does not enable/disable scrolling. It sets the caret to the
end, therefore the end is made visible by DefaultCaret.adjust-
Visibility. If the Caret happened to be at the end before that
call (as it may well be), the call has no effect.
Read the thread starting with
http://groups.google.com/groups?selm=3C04EEE5.9893AFC1%40addcom.de
Christian
|
|
0
|
|
|
|
Reply
|
usenet
|
8/19/2004 3:48:45 PM
|
|
Hi Christian,
I don't get it. In the API I can read the following comment for adjustVisibility:
"Scrolls the associated view (if necessary) to make the caret visible. Since
how this should be done is somewhat of a policy, this method can be
reimplemented to change the behavior. By default the scrollRectToVisible
method is called on the associated component. "
I replementated the method adjustVisibility for invocation
MyTextPane txtPane = new MyTextPane();
txtPane.adjustVisibility(null);
class MyTextPane extends JTextPane {
public void adjustVisibility(Rectangle rec) {
}
}
But it's still scrolling! :-)
Thomas
|
|
0
|
|
|
|
Reply
|
Thomas
|
8/20/2004 7:23:24 AM
|
|
> I don't get it. In the API I can read the following comment for
adjustVisibility:
> "Scrolls the associated view (if necessary) to make the caret visible.
Since
> how this should be done is somewhat of a policy, this method can be
> reimplemented to change the behavior. By default the scrollRectToVisible
> method is called on the associated component. "
>
> I replementated the method adjustVisibility for invocation
>
> MyTextPane txtPane = new MyTextPane();
> txtPane.adjustVisibility(null);
>
> class MyTextPane extends JTextPane {
>
> public void adjustVisibility(Rectangle rec) {
>
> }
> }
>
> But it's still scrolling! :-)
adjustVisibility is method of DefaultCaret, not of JTextPane.
as I also mentioned you can override scrollRectToVisible of JTextPane.
Or you can install your own Caret with empty adjustVisibility.
class NonSrollingCaret extends DefaultCaret {
public void adjustVisibility(Rectangle rec) {}
}
JTextPane textPane = new JTextPane();
textPane.setCaret(new NonSrollingCaret());
--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
|
0
|
|
|
|
Reply
|
ak
|
8/20/2004 12:45:58 PM
|
|
|
6 Replies
801 Views
(page loaded in 0.067 seconds)
|
|
|
|
|
|
|
|
|