kazoo
kazoo

Reputation: 137

Deactivate ScrollOnExpand on JScrollPane

I want to prevent the scrollpane from scrolling when the content in its view expands. Any pointers? I've tried Googling variations on the title, as well as reading all the docs for JScrollPane, and I'm still a bit baffled.

Edit: Within the scroll pane, I have a textpane, and beside it I have another text pane that shows the line numbers of the pane beside it. I fill up this number pane every time a new line is added, so this is probably what is causing the view to advance.

Upvotes: 3

Views: 110

Answers (2)

kleopatra
kleopatra

Reputation: 51525

to-scroll or not-to-scroll is configurable on DefaultCaret

    DefaultCaret caret = (DefaultCaret) textPane.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

See also Rob's nice blog entry about text scrolling

Upvotes: 2

Ingo Kegel
Ingo Kegel

Reputation: 47975

Usually JScrollPane does not do that, the getViewport().getViewPosition() remains fixed when you enlarge the view port with code like

JScrollPane scrollPane = ...;
scrollPane.getViewport().getView().setPreferredSize(...);
scrollPane.getViewport().revalidate();

Maybe your component changes in such a way that you perceive it as "scrolling". In that case you have to adjust the view position with scrollPane.getViewport().setViewPosition(...) after enlarging the view..

Upvotes: 0

Related Questions