如何在java中将字母间距样式设置为jediterpane?

时间:2014-01-27 13:48:26

标签: java swing jtextpane jeditorpane

我向jeditorpane添加了一条css规则。但只有身体规则有效。其他人没有。

Font body_font = new Font("Courier New", Font.PLAIN, 8);
String bodyRule = "body { font-family: " + body_font.getFamily() + "; "
        + "font-size: " + body_font.getSize() + "pt;}";
((HTMLDocument) jEditorPane1.getDocument()).getStyleSheet().addRule(bodyRule);
String P_Rule = "P {letter-spacing:3px}";
((HTMLDocument) jEditorPane1.getDocument()).getStyleSheet().addRule(P_Rule);
String h5_Rule = "H5 {letter-spacing:3px}";
((HTMLDocument) jEditorPane1.getDocument()).getStyleSheet().addRule(h5_Rule);
MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set, -0.2f);
StyleConstants.setFontFamily(set, "Courier New");
StyleConstants.setFontSize(set, 10);
set.addAttribute(TextAttribute.TRACKING, 0.5);
((HTMLDocument) jEditorPane1.getDocument()).setParagraphAttributes(0, jEditorPane1.getDocument().getLength(), set, true);

0 个答案:

没有答案