Java 在DefaultStyledDocument上设置字体颜色

Java 在DefaultStyledDocument上设置字体颜色,java,swing,defaultstyleddocument,Java,Swing,Defaultstyleddocument,我知道我可以在javax.swing.text.DefaultStyledDocument上设置字体大小,如下所示: public void apply(DefaultStyledDocument document) { final MutableAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setFontSize(attributeSet, 12); document.setCh

我知道我可以在
javax.swing.text.DefaultStyledDocument
上设置字体大小,如下所示:

public void apply(DefaultStyledDocument document) {
    final MutableAttributeSet attributeSet = new SimpleAttributeSet();
    StyleConstants.setFontSize(attributeSet, 12);
    document.setCharacterAttributes(0, 80, attributeSet, false);
}

如何设置字体颜色?

我猜您使用StyleConstants.setForeground(…)方法。

我猜您使用StyleConstants.setForeground(…)方法