Search code examples
javaswingjtextpanecaret

Change Text Cursor Size in JTextPane


I'm making a simple text editor, and I have a JTextPane and changed the spacing to 1.5f. The only problem is that the "Text Cursor" spans all the pixels from the current line to the next one, regardless of font size. Here's an example:

Large Cursor

Is there anyway I can make the text cursor size automatically adjust to the text size?


Solution

  • See here http://java-sl.com/tip_overwrite_mode.html how to change caret shape.

    Alternatively yu can override modelToView method to correct returned rectangle's shape (height).