RYN*_*RYN 4 java swing scroll jeditorpane htmleditorkit
您好
我使用带有HTMLEditorKit的JEditorPane来显示能够包装文本的HTML文本.
问题是,当我使用.setText方法设置内容时,它会自动滚动到该文本的末尾.
我怎么能禁用它?
谢谢.
您可以尝试这个技巧来保存光标位置setText()
,然后在将文本添加到组件后将其恢复:
int caretPosition = yourComponent.getCaretPosition();
yourComponent.setText(" your long text ");
yourComponent.setCaretPosition(Math.min(caretPosition, text.length()));
Run Code Online (Sandbox Code Playgroud)
尝试这个:
final DefaultCaret caret = (DefaultCaret) yourEditorPane.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
//!!!!text must be set AFTER update policy has been set!!!!!
yourEditorPane.setText(text);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2163 次 |
最近记录: |