2011-12-15 67 views
2
JTextArea txt = new JTextArea(); 
    StringBuffer sb = new StringBuffer(); 
    sb.append("Employee Information"); 
    sb.append("\n"); 
    sb.append("Name:"); 
    txt.setText(sb.toString()); 

在這裏,我需要設置「員工信息」大膽format..How做到這一點.. 我想這樣如何在JTextArea中設置風格(使粗體)文本?

sb.append("<html><b>Employee Information</b></html>"); 

但其打印文本通常...如何大膽?

+0

http://stackoverflow.com/questions/2713863/java-jtextarea-bold – 2011-12-15 05:24:45

+0

我嘗試.. JEditorPane textarea =新的JEditorPane(「文本/ HTML」,「」); textarea.setText(「Here is bold text」); sb.append(「員工信息」); sb.append(「\ n」); sb.append(「Name:」); textArea.setText(sb.toString());但它沒有來.. – shree

+1

感謝我得到它..它工作... – shree

回答

3

可以使用setFont方法。對於示例嘗試:

Font font = txt.getFont(); 
txt.setFont(font.deriveFont(Font.BOLD)); 

(請記住,txtJTextArea,不是你的實際文本。)

相關問題