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.