简体   繁体   English

在DefaultStyledDocument上设置字体颜色

[英]Setting font color on DefaultStyledDocument

I know that I can set the font size on a javax.swing.text.DefaultStyledDocument like this: 我知道我可以像这样在javax.swing.text.DefaultStyledDocument上设置字体大小:

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

How do I set the font color? 如何设置字体颜色?

我猜你会使用StyleConstants.setForeground(...)方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM