本文介绍了向BorderLayout.SOUTH添加JTextPane会导致JScrollPane滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含在JScrollPane中的JPanel。 JPanel的组件已添加到其NORTH,CENTER,WEST和SOUTH区域(BorderLayout)。
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).
当我将JTextPane添加到SOUTH位置时,滚动窗格会滚动显示文本。我不希望滚动窗格从其最顶端位置移动。我该如何防止这种情况?
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?
推荐答案
如果没有更多细节,您可以尝试将默认插入符号设置为,自Java 5起可用。
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);
这篇关于向BorderLayout.SOUTH添加JTextPane会导致JScrollPane滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!