1

だから私は JTextPane のテキストをダブルスペースにしようとしています。これが私のコードです:

     MutableAttributeSet attrs = editor.getInputAttributes();
     StyleConstants.setLineSpacing(attrs, 2);
     editor.getStyledDocument().setParagraphAttributes(0, doc.getLength() + 1, attrs, true);

これに関する問題は、カーソル (キャレット) が 3 行または 4 行のスペースと同じくらい大きいことです。キャレットのサイズを通常のサイズに変更するにはどうすればよいですか?

ここにスクリーンスニップがあります

ここに画像の説明を入力

4

1 に答える 1

2

これを試して:

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);
    }
});
于 2012-08-04T14:29:24.767 に答える