在 SWT 标签中显示 HTML 文本 [英] Display HTML text in SWT Label
问题描述
我想在 Java SWT 标签中显示 HTML 文本.下面是我创建标签的代码.
Label theLabel = new Label(controls,SWT.WRAP);theLabel.setSize(100,500);theLable.setText("<html><ol><li>你好</li><li>欢迎</li></ol></html>");
当我将应用程序作为 Eclipse 应用程序运行时,我得到的输出为:
- Hello
- 欢迎光临
错误是什么?为什么我的标签中没有 html 格式的输出?我正在使用带有视图的 Eclipse 插件.
要使用 SWT 显示 HTML,您必须使用 浏览器小部件.
Browser browser = new Browser( parent, SWT.NONE );browser.setText( "<html><ol><li>你好</li><li>欢迎</li></ol></html>");
如果您不介意对 org.eclipse.ui.forms
的额外依赖,您也可以使用 FormText.但请注意,该控件仅理解 HTML 的一个子集(、
、
、
、
、) 来呈现简单的格式化文本.
I would like to display the HTML text in a Java SWT Label. Below is my code for creating a label.
Label theLabel = new Label(controls,SWT.WRAP);
theLabel.setSize(100,500);
theLable.setText("<html><ol><li>Hello</li><li>welcome</li></ol></html>");
When I run the application as Eclipse Application I get the output as:
<html><ol><li>Hello</li><li>welcome</li></ol></html>
What is the mistake? Why I am not getting the html formatted output in my label? I am using Eclipse plugin with a view.
To show HTML with SWT you will have to use the Browser widget instead.
Browser browser = new Browser( parent, SWT.NONE );
browser.setText( "<html><ol><li>Hello</li><li>welcome</li></ol></html>" );
If you don't mind the extra dependency on org.eclipse.ui.forms
you can also use FormText. But be aware that the control does only understand a subset of HTML (<p>
, <b>
, <li>
, <img>
, <br>
, <span>
) to render simple formatted text.
这篇关于在 SWT 标签中显示 HTML 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!