开发者

Java JTextArea hightliting text with a bold font

开发者 https://www.devze.com 2023-01-22 11:48 出处:网络
I need several words to be highlighted in a String while appending it to a JTex开发者_如何学编程tArea. So that I try this:

I need several words to be highlighted in a String while appending it to a JTex开发者_如何学编程tArea. So that I try this:

jta.append("<html> <b>Termination time : </b></html>" + 
                        CriterionFunction.estimateIndividual_top(individual) + "\n");

Where jta is a JTextArea. The output I get is: <html> <b>Termination time : </b></html> 15

I have read some forum articles about such a problem, and it was said that <html><b> </b></html> would help. But it doesn't.

Please, tell me. where is my mistake?


You should use a JEditorPane instead of your JTextArea.

The following shall work:

    JEditorPane jep = new JEditorPane();
    jep.setContentType("text/html");
    jep.setText("<html> <b>Termination time : </b></html>" + CriterionFunction.estimateIndividual_top(individual) + "\n");
0

精彩评论

暂无评论...
验证码 换一张
取 消