Adding a JTextPane to BorderLayout.SOUTH causes JScrollPane to scroll

最后都变了- 提交于 2019-12-04 06:00:56

问题


I have a JPanel which is contained within a JScrollPane. The JPanel has components added to it's NORTH, CENTER, WEST and SOUTH areas (BorderLayout).

When I add a JTextPane to the SOUTH position, the scroll pane scrolls to show the text. I do not want the scroll pane to move from its topmost position. How can I prevent this?


回答1:


Absent more details, you can try setting the default caret to NEVER_UPDATE, available since Java 5.

JTextPane jtp = new JTextPane();
DefaultCaret caret = (DefaultCaret) jtp.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);


来源:https://stackoverflow.com/questions/11299311/adding-a-jtextpane-to-borderlayout-south-causes-jscrollpane-to-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!