When I try to use HTML with `JOptionPane`, HTML tags are printed instead of HTML formatting

The entire string needs to be enclosed within the HTML tags. For example:

button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");

For more information, see How to Use HTML in Swing Components.


Also worth noting: it seems that having a newline in your string triggers JOptionPane to not render the string as HTML, whereas e.g. JLabel does allow newlines in the HTML.


Enclose your entire string within html tags.