Java JTextPane-使插入符号大小正常?
因此,我尝试将JTextPane中的文本设置为双倍行距。这是我的密码:Java JTextPane-使插入符号大小正常?,java,swing,cursor,jtextpane,Java,Swing,Cursor,Jtextpane,因此,我尝试将JTextPane中的文本设置为双倍行距。这是我的密码: MutableAttributeSet attrs = editor.getInputAttributes(); StyleConstants.setLineSpacing(attrs, 2); editor.getStyledDocument().setParagraphAttributes(0, doc.getLength() + 1, attrs, true); 问题是,游标(插入符号)
MutableAttributeSet attrs = editor.getInputAttributes();
StyleConstants.setLineSpacing(attrs, 2);
editor.getStyledDocument().setParagraphAttributes(0, doc.getLength() + 1, attrs, true);
问题是,游标(插入符号)有三到四行空格那么大。如何将插入符号调整为正常大小
这是一个屏幕剪报
试试这个:
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);
}
});