本文介绍了JTextPane - 使插图正常大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想让文本在JTextPane双间隔。这里是我的代码:

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);

问题是,curser(插入符号) 。

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?

这里是一个屏幕截图

推荐答案

试试这个:

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);
    }
});

这篇关于JTextPane - 使插图正常大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:20