日期:2014-05-20  浏览次数:20695 次

关于JTextPane的setLeftIndent 没有实现缩进
我用下面的一段代码,发现我可以加粗,设置字体大小,改变颜色,但是如果是缩进,或者是行距什么的
却无法实现,我不懂为什么会这样,有知道的人能帮帮忙说一下原因吗?


SimpleAttributeSet attrSet = new SimpleAttributeSet(); 
StyleConstants.setLeftIndent(attrSet, 30); //无法实现缩进
StyleConstants.setBold(attrSet, true); //可以实现字体加粗
StyleConstants.getLeftIndent(attrSet); //得到值是30
Document doc = msgArea.getDocument();  
try {  
  doc.insertString(doc.getLength(), "要缩进的字符", attrSet);  
}catch (BadLocationException e) {  
  System.out.println("BadLocationException: " + e);  
}



------解决方案--------------------
可以看一下这个例子:

http://www.java2s.com/Code/JavaAPI/javax.swing.text/StyleConstantssetLeftIndentMutableAttributeSetafloati.htm