Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

How to disable automatic scrolling of JScrollPane / JTextPane (Swing)

Thread view: 
ODB - 21 Jun 2005 20:44 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.