Hi,
I want to be able to enable / disable the automatic scrolling performed when
adding text to a JTextPane. A JScrollPane has a viewport set to the
textpane. The text is added within a thread invoked using
SwingUtilities.invokeLater(...). Only the automatic scrolling should be
disabled, the user must still be able to scroll using the scrollbars etc.
and be able to enable the automatic scrolling again. (I'm using
jdk1.5.0_03.)
Here is how some parts my code look like:
...
<init>
...
jTextPane = new JTextPane();
JScrollPane jScrollPane = new JScrollPane();
jScrollPane.setViewportView(textPane);
...
<some-method>
...
StyledDocument styledDocument = (StyledDocument)jTextPane.getDocument();
...
<call addText-method>
...
<addText-method>
...
Runnable r = new Runnable() {
public void run() {
try {
styledDocument.insertString(styledDocument.getLength(), text,
style);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
};
SwingUtilities.invokeLater(r);
...
Every time the <addText-method> is called the JScrollPane scrolls to the end
of the document. How can I enable / disable that automatic scrolling and
still use a thread / invokeLater to add the text?
Greetings,
ODB
margielm - 22 Jun 2005 09:03 GMT
here is a solution for your problem:
JTexyPane jTextPane1 = new JTextPane();
jTextPane1.setAutoscrolls(false);
> Hi,
>
[quoted text clipped - 45 lines]
>
> ODB
ODB - 22 Jun 2005 12:33 GMT
> here is a solution for your problem:
>
> JTexyPane jTextPane1 = new JTextPane();
> jTextPane1.setAutoscrolls(false);
Hmmm... Do you have any idea what my problem is and what the setAutoscrolls
method does??? The setAutoscrolls method was my first guess, but if you look
at the specs you'll see that this method does something else.
ODB