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 / September 2005

Tip: Looking for answers? Try searching our database.

Disabling scrolling of a JTextPane when document is updated

Thread view: 
Alexander Avtanski - 08 Sep 2005 20:04 GMT
Hello,

I have the following problem, that I try to resolve unsuccessfully
for some time:

I have a JTextPane in a JScrollPane.  When I use setText() to update
the text in, the JTextPane gets scrolled to the end (last line).
I'm trying to suppress this - what I need is to have the scroll
bar remaining in the same state as before.

I tried removing all listeners that I could come up with (for example,
the CaretListener), tried extending JTextPane and overwriting the
fireCaretUpdate() method with an empty one - none of this worked.

Any ideas?

Thanks,

- Alex
Vova Reznik - 08 Sep 2005 21:12 GMT
> Hello,
>
[quoted text clipped - 15 lines]
>
> - Alex

if you want to keep scroll in its position
then remeber position, load text, call scrollBar setValue.
setValue should be called from EventQueue
    // --- load text --

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                scroll.getVerticalScrollBar().setValue(pos);
            }
        });
Alexander Avtanski - 08 Sep 2005 21:40 GMT
> [ ... ]
>
[quoted text clipped - 8 lines]
>             }
>         });

Thanks!  It worked perfectly!  :-)

- Alex


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.