HTML in JLabel not displaying
JLabel label = new JLabel("<html><body>Hello world</body></html>");
nothing is displayed.
If I get rid of the tags, it shows plain text (as expected), so JLabel is definitely added and displayed in the window.
The same goes for:
JEditorPane jep = new JEditorPane("text/html", "<html><body>Hello world</body></html>");
Any ideas?
I am using java-6-openjdk with Eclipse. More details:
matt@matt-laptop:~$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1~10.04.1)
OpenJDK Server VM (build 19.0-b09, mixed mode)
matt@matt-laptop:~$ javac -version
javac 1.6.0_24
If you want to mix fonts or colors in the text, or if you want formatting such as multiple lines, you can use HTML. HTML formatting can be used in all Swing buttons, menu items, labels, tooltips, and tabbed panels, as well as in components such as trees and tables that use labels to render text.
JLabel label = new JLabel("<html><body>Hello world</body></html>");
- , <b>bold</b> <i>italic</i> ..
<body></body> .
, .