TheGaME
TheGaME

Reputation: 453

Display HTML text in SWT Label

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.

Upvotes: 4

Views: 4030

Answers (1)

R&#252;diger Herrmann
R&#252;diger Herrmann

Reputation: 20985

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.

Upvotes: 7

Related Questions