本文介绍了JLabel中的HTML未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JLabel label = new JLabel(< html>< body> Hello world< / body>< / html>);
没有任何显示。
如果我得到摆脱标签,它显示纯文本(如预期),所以JLabel肯定会被添加并显示在窗口中。
相同:
JEditorPane jep = new JEditorPane(text / html,< html>< body> Hello world< / body>< / html> ;);
有什么想法?
我是在Eclipse中使用java-6-openjdk。更多细节:
matt @ matt-laptop:〜$ java -version
java version1.6.0_20
OpenJDK运行环境(IcedTea6 1.9.5)(6b20-1.9.5-0ubuntu1〜10.04.1)
OpenJDK服务器虚拟机(构建19.0-b09,混合模式)
亚光@ matt-laptop:〜$ javac -version
javac 1.6.0_24
解决方案
请参阅此示例
在您的示例中
JLabel label = new JLabel(< html>< body> ; Hello world< / body>< / html>);
您不会像< b>粗体< / b> ;
或者< i>斜体< / i>
等等。
< body>< / body>
不是必需的。
希望它有帮助。 b $ b
JLabel label = new JLabel("<html><body>Hello world</body></html>");
shows nothing.
If I get rid of the tags, it shows plain text (as expected), so the JLabel is definitely being added and shown on the window.
Same for:
JEditorPane jep = new JEditorPane("text/html", "<html><body>Hello world</body></html>");
Any ideas?
I'm 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
解决方案
Refer this example HtmlDemo.java
In your example
JLabel label = new JLabel("<html><body>Hello world</body></html>");
you are not applying any formating like <b>bold</b>
or <i>italic</i>
etc..
also <body></body>
is not required.
Hope it helps.
这篇关于JLabel中的HTML未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!