Hi
I used a JEditorPane with HTMLEditorKit to showing HTML text with ability to wrap text.
The problem is when I set it's content using .setText method it automatically scrolls to the end of that text.
How can I disable this?
Thanks.
You can try this trick to save the cursor position before the setText()
and then restore it once you've added your text to the component:
int caretPosition = yourComponent.getCaretPosition();
yourComponent.setText(" your long text ");
yourComponent.setCaretPosition(Math.min(caretPosition, text.length()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With