用的是SWT中的org.eclipse.swt.browser.Browser組件html
String html="<table><tr><td>你好</td></tr></table>";shell
Browser browser = new Browser(shell, SWT.NONE);app
browser.setText(html);eclipse
完整示例代碼以下:ide
- package test.ftp00;
- 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 RenderHTML {
- public static void main(String[] args) {
- /* Relative links: use the HTML base tag */
- // String html =
- // "<iframe src="/" mce_src="http://www.thinkpage.cn/weather/weather.aspx?c=CHXX0008&l=zh-CN&p=MSN&a=0&u=C&s=1&m=1&x=1&d=3&fc=&bgc=&bc=/" frameborder=/"0/" scrolling=/"no/" width=/"200/" height=/"260/" allowTransparency=/"true/"></iframe>";
- // html =
- // "<embed allowScriptAccess=/"never/" allowNetworking=/"internal/" pluginspage=http://www.macromedia.com/go/getflashplayer src="/" mce_src="/""http://aw.awflasher.com/getweatherc.swf?awstyle=blue/" width=/"180/" height=/"200/" type=application/x-shockwave-flash></embed>";
- String html="<table><tr><td>你好</td></tr></table>";
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- Browser browser = new Browser(shell, SWT.NONE);
- browser.setText(html);
- shell.setSize(260, 350);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
- }