JTextArea我希望我的文本部分是粗体或草书

时间:2016-06-14 18:15:46

标签: java swing jtextarea

我遇到了JTextArea的问题。我不知道如何将JTextArea中的部分文本更改为粗体或草书。任何人吗?

1 个答案:

答案 0 :(得分:1)

使用Simple Attributes更改文字字体和颜色。像

SimpleAttributeSet attrSet= new SimpleAttributeSet();
StyleConstants.setFontFamily(attrSet, "Courier New Italic");
StyleConstants.setForeground(attrSet, Color.BLUE);

textArea.getDocument().insertString(0, "Your text is here", attrSet);

或者,您将获得更多advantage and flexibility, if you use editor or text panes

相关问题