I learnt something new about Swing yesterday
I had a little task to update some of a colleague's code yesterday, which involved adding a new message to be displayed in a JOptionPane. I noticed, and was puzzled by the fact that there were messages in the file which had HTML constructs in them. These messages are displayed in a JOptionPane too.
At first, I ignored the HTML constructs, assuming that the HTML was somehow filtered. However, when I queried my colleague on it, it turned out that you can indeed use limited HTML in Swing components, and it is documented in the manual. I guess I just haven't looked at the JLabel API docs for so long that I missed the change.
In the end, I didn't need the HTML, because I only wanted basic multiline presentation in the JOptionPane, which you can achieve by interspersing the string "\n" in your text. For example:
String msg = "This is a\nmulti-line\nmessage.";
My colleague was trying to do the same multi=line display, but using HTML:
String msg = "<html>This is a<br>multi-line<br>message.</html>";
I may not have needed it, but I'm sure I will find a use for it in the future, so it's nice to know.
Posted by Geertjan on April 08, 2005 at 05:00 PM BST #
Posted by Eric Hancock on April 08, 2005 at 06:04 PM BST #