开发者

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜