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 / March 2007

Tip: Looking for answers? Try searching our database.

Scrolling JTextPane inside a JScrollPane manually

Thread view: 
loquak - 08 Mar 2007 12:19 GMT
Hi.
I'm trying to apply a feature where the dialog (containing one
JTextPane) remembers the last vertical scroll position of the pane. When
the dialog is re-opened, the pane will automatically be scrolled down to
the position where it was before closing the dialog.

Logically, I thought the following would do the trick:

On close:
lastPos.pos = scrollPane.getViewport().getViewPosition(); (lastPos.pos =
Point)

On re-open:
scrollPane.getViewport().setViewPosition(new Point(0,0));

Didn't work, so I tried the following:

On close:
lastPos.pos = scrollPane.getVerticalScrollBar().getValue(); (lastPos.pos
 = int)

On re-open:
scrollPane.getVerticalScrollBar().setValue(lastPos.pos);

Didn't work either! So, logically again, I'm out of ideas. Any tips? (I
have no use for setCaretPosition and getCaretPosition since the caret
won't be used, as the pane is read-only)
loquak - 08 Mar 2007 12:21 GMT
loquak kirjoitti:
> Hi.
> I'm trying to apply a feature where the dialog (containing one
[quoted text clipped - 10 lines]
> On re-open:
> scrollPane.getViewport().setViewPosition(new Point(0,0));

Should be
scrollPane.getViewport().setViewPosition(lastPos.pos);

> Didn't work, so I tried the following:
>
[quoted text clipped - 8 lines]
> have no use for setCaretPosition and getCaretPosition since the caret
> won't be used, as the pane is read-only)
loquak - 08 Mar 2007 13:51 GMT
loquak kirjoitti:
> Hi.
> I'm trying to apply a feature where the dialog (containing one
[quoted text clipped - 23 lines]
> have no use for setCaretPosition and getCaretPosition since the caret
> won't be used, as the pane is read-only)

        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                scrollPane.getVerticalScrollBar().setValue(lastPos.pos);
            }           
        });

did the trick!
phengtang@gmail.com - 19 Mar 2007 14:36 GMT
> loquak kirjoitti:
>
[quoted text clipped - 37 lines]
>
> - Show quoted text -

I have the same pb, and the work-around SwingUtilities.invokeLater
works fine, Thanks.


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.