HTMLRendererInMemory.java Source code

Java tutorial

Introduction

Here is the source code for HTMLRendererInMemory.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class HTMLRendererInMemory {
    public static void main(String[] args) {
        String html = "<HTML><HEAD><TITLE>HTML Test</TITLE></HEAD><BODY>";
        for (int i = 0; i < 100; i++) {
            html += "<a href=\"http://www.java2s.com\">java2s.com</a><br><br>";
        }
        html += "</BODY></HTML>";

        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        Browser browser = new Browser(shell, SWT.NONE);
        browser.setText(html);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}