更改JTextArea中特定行的字体 [英] change font of specific lines in JTextArea
本文介绍了更改JTextArea中特定行的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
setFont()
函数,但它改变了TextArea中所有字符串的字体。所以我只是想改变只有我的font.i,如果你可以帮助我感激。解决方案
那么我想我必须学习litte HTML
我不会使用HTML。处理文本窗格时,我发现使用属性更容易。属性更容易改变,然后试图操作HTML。
pre $ c $ SimpleAttributeSet
StyleConstants.setFontFamily(绿色,Courier New Italic);
StyleConstants.setForeground(green,Color.GREEN);
//添加一些文本
尝试
{
textPane.getDocument()。insertString(0,带有Courier字体的绿色文本,绿色);
catch(例外e){}
hi there ı am working on a chat application and i want that user can change the font which he/she is writing. there is a setFont()
function but it changes font of all strings in the TextArea. so i just want to change only my font.i appreciated if you can help me.
解决方案
well then i guess i must learn a litte HTML
I wouldn't use HTML. I find it easier to just use attributes when dealing with a text pane. Attributes are much easier to change then trying to manipulate HTML.
SimpleAttributeSet green = new SimpleAttributeSet();
StyleConstants.setFontFamily(green, "Courier New Italic");
StyleConstants.setForeground(green, Color.GREEN);
// Add some text
try
{
textPane.getDocument().insertString(0, "green text with Courier font", green);
}
catch(Exception e) {}
这篇关于更改JTextArea中特定行的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文