When customized caret is set by setCaret(), it registers its
DocumentListener for position update. Then, that DocumentListener is called
*before* the listener for the views(e.g.
BasicTextUI$UpdateHandler.insertUpdate()). So when the
DefaultCaret.insertUpdate() is called, there can be a mismatch between the
model structure and view structure. This causes modelToView return null
rectangle and DefaultCaret.damage() will not cause repaint(). The default
order of DocumentListeners is that the listener for the views is first, and
the listener for the caret is next. So this problem does not happen.
I attached a sample program to reproduce this problem. To reproduce,
1) Compile the sourc
2) Run at the command shell as 'java CaretTest'
3) When the window appears, click the JTextPane
4) Input some characters(other than 's')
5) Then input "s", this will install customized caret.
6) Type any character, you will see the caret is drawn incorrectly.