你好
我使用带有 HTMLEditorKit 的 JEditorPane 来显示具有换行功能的 HTML 文本。
问题是当我使用 .setText 方法设置它的内容时,它会自动滚动到该文本的末尾。
我怎样才能禁用它?
谢谢。
最佳答案
您可以尝试这个技巧来保存 setText()
之前的光标位置,然后在将文本添加到组件后恢复它:
int caretPosition = yourComponent.getCaretPosition();
yourComponent.setText(" your long text ");
yourComponent.setCaretPosition(Math.min(caretPosition, text.length()));
关于java - 在 JEditorPane 中禁用滚动到文本末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5350722/