[英]Display HTML text in SWT Label
I would like to display the HTML text in a Java SWT Label. 我想在Java SWT标签中显示HTML文本。 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: 当我将应用程序作为Eclipse Application运行时,我得到的输出为:
<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?
为什么我没有在标签中获得html格式的输出? I am using Eclipse plugin with a view.
我正在使用带有视图的Eclipse插件。
To show HTML with SWT you will have to use the Browser widget instead. 要使用SWT显示HTML,您必须使用“ 浏览器”窗口小部件 。
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 . 如果你不介意对
org.eclipse.ui.forms
的额外依赖,你也可以使用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. 但请注意,控件只能理解HTML的一个子集(
<p>
, <b>
, <li>
, <img>
, <br>
, <span>
)来呈现简单的格式化文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.