Resize text cursor in JTextPane

I am making a simple text editor and I have a JTextPane and change the interval to 1.5f. The only problem is that the Text Cursor spans all the pixels from the current line to the next, regardless of the font size. Here is an example:

Large cursor

Is it possible in any case to change the size of the text cursor to the size of the text?

+4
source share
2 answers

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

Alternatively, yu can override the modelToView method to adjust the shape of the rectangle (height).

+2
source

A "text cursor" is usually called a "carriage" in GUI libraries. The same thing in a swing. You can use the setCaret method to change it. To change the look, inherit from javax.swing.text.DefaultCaret and override the paint method.

+2
source

All Articles