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 vie开发者_运维知识库w to advance.
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
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..
精彩评论