我对JTextArea有问题。我不知道如何更改JTextArea中的部分文本为粗体或草书。任何人?
最佳答案
使用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。