问题
JTextArea txt = new JTextArea();
StringBuffer sb = new StringBuffer();
sb.append("Employee Information");
sb.append("\n");
sb.append("Name:");
txt.setText(sb.toString());
Here I need to set "Employee Information" to BOLD format..How to do that.. I tried like this
sb.append("<html><b>Employee Information</b></html>");
But its printing the text normally... how to make bold?
回答1:
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
回答2:
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.)
来源:https://stackoverflow.com/questions/8515477/how-to-stylize-make-bold-text-in-a-jtextarea