JLabel中的HTML未显示 [英] HTML in JLabel not showing

查看:189
本文介绍了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


解决方案


如果您想在文本中混合使用字体或颜色
,或者您想要
格式(例如多行),则
可以使用HTML。在所有Swing按钮,菜单项,
标签,工具提示和选项卡式窗格,
以及诸如树
和使用的表格中使用的HTML格式可以是
标签来呈现
文本。


请参阅此示例 HtmlDemo.java






在您的示例中

  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

解决方案

If you want to mix fonts or colors within 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, tool tips, and tabbed panes, as well as in components such as trees and tables that use labels to render text.

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未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆