普通文本框和文本域设置不了字体颜色,需要用TextPane
文本窗格继承自编辑器窗格
public class JTextPane extends JEditorPane
样例:
MutableAttributeSet attrRed = new SimpleAttributeSet();
StyleConstants.setForeground(attrRed, Color.RED);
this.jTextPane1.getDocument().insertString(this.jTextPane1.getDocument().getEndPosition().getOffset()-1,"\n正在比较……\n",attrRed);
参考:
Swing对JTextPane中字体颜色的设置
http://www.blogjava.net/Swing/archive/2007/07/09/128965.html
本文介绍如何使用Swing中的JTextPane组件来设置文本的颜色,并提供了一个具体的样例代码,展示了如何通过设置属性来改变文本的颜色。
1518

被折叠的 条评论
为什么被折叠?



