读书人

关于JTextPane的setLeftIndent 没实现

发布时间: 2012-11-16 14:12:15 作者: rapoo

关于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

读书人网 >J2SE开发

热点推荐