2012-08-04 75 views
1

所以我試圖使JTextPane中的文本加倍間隔。這是我的代碼:JTextPane - 製作插入符號的大小?

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

這個問題是,光標(插入符號)是三個或四個行空格一樣大。如何將脫字符調整爲正常大小?

這裏是一個屏幕剪斷

enter image description here

回答

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