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

如何在java中将字母间距样式设置为jediterpane?,java,swing,jtextpane,jeditorpane,Java,Swing,Jtextpane,Jeditorpane,我将css规则添加到jeditorpane。但只有身体法则起作用。其他人没有 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) jEditorPan

我将css规则添加到
jeditorpane
。但只有身体法则起作用。其他人没有

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

P
H5
标签在哪里?在
主体内部
?我不确定,但您是否尝试过使用小写的
p
h5
?我在绝地窗格中显示的Html内容中使用了p和h5。。使用此选项可添加紧排效果