How to leave part of the JLabel text in bold

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 code snippet prints the 'b' on the screen too.

    
asked by anonymous 11.08.2017 / 16:55

1 answer

3

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

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

However, I suggest using alternate components, which allow you to do this without messing up code with these html's strings: JTextPane or JEditorPane . In this answer there is an example of using one of these components and what they are capable of to do.

    
11.08.2017 / 16:58