How to make part of the Jlabel text bold

Asked

Viewed 1,273 times

2

Is there any way to leave only a portion of the bold text of a Jlabel?

For example:

label.setText("apenas esta parte em <b>negrito</b>");

But this snippet of code prints the 'b' on the screen too.

1 answer

3


You need to wrap the whole text between the tags <html> and </html>:

label.setText("<html>apenas esta parte em <b>negrito</b></html>");

However, I suggest using alternative components, which allow you to do this without soiling the code with these individual html snippets: JTextPane or JEditorPane. In this answer there is an example of using one of these components and of what they are able to do.

  • Thank you, I had no idea it would be so simple

  • @P.Dominges yes, but it is good to use only for sporadic cases, since these excerpts make it difficult to read and maintain the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.