Reputation: 1387
So I am trying to make the text in a JTextPane double spaced. Here's my code:
MutableAttributeSet attrs = editor.getInputAttributes();
StyleConstants.setLineSpacing(attrs, 2);
editor.getStyledDocument().setParagraphAttributes(0, doc.getLength() + 1, attrs, true);
The problem with this, is, the curser (caret) is as big as three or four line spaces. How can I resize the caret to normal size?
Here is a screen snip
Upvotes: 1
Views: 599
Reputation: 15490
Try this:
editor.setCaret(new DefaultCaret() {
public void paint(Graphics g) {
JTextComponent comp = getComponent();
if (comp == null)
return;
Rectangle r = null;
try {
r = comp.modelToView(getDot());
if (r == null)
return;
} catch (BadLocationException e) {
return;
}
r.height = 15; //this value changes the caret size
if (isVisible())
g.fillRect(r.x, r.y, 1, r.height);
}
});
Upvotes: 2