How to stylize (make bold) text in a JTextArea?

前端 未结 2 1372
挽巷
挽巷 2021-01-22 21:41
JTextArea txt = new JTextArea();
    StringBuffer sb = new StringBuffer();
    sb.append(\"Employee Information\");
    sb.append(\"\\n\");
    sb.append(\"Name:\");
            


        
相关标签:
2条回答
  • 2021-01-22 22:13

    You can use the setFont method. For your example try :

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

    (Keep in mind that txt is the JTextArea, not your actual text.)

    0 讨论(0)
  • 2021-01-22 22:35

    The JText Area is a plain text area, for styled text areas you need something like JEditorPane or JTextPane, take a look at the Documentation

    0 讨论(0)
提交回复
热议问题