Java web browser with XULRunner

1.2k views Asked by At

I need to create a web browser with XULRunner (or another rendering engine) using Java, but I don't have any experience with it. All I need is to open a full screen Java Panel, to load XULRunner (or another web rendering engine) inside it and to load a local Web Page there.

Somebody can help me to start? Unfortunately, I haven't so much time to try alone...

1

There are 1 answers

5
Christian Kuetbach On BEST ANSWER

Which java GUI framework do you use?

There is a (Mozilla-) Browser implemented in SWT. You also can create this Browser within Swing:

import javax.swing.JFrame;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BrowserSwingPanel {

   public static void main(String args[]) {

      JFrame f = new JFrame();
      f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
      Canvas canvas = new Canvas();
      f.setSize(500, 400);
      f.add(canvas);
      f.setVisible(true);
      Display display = new Display();
      Shell shell = SWT_AWT.new_Shell(display, canvas);
      shell.setSize(500, 400);
      Browser browser = new Browser(shell, SWT.NONE);
      browser.setSize(500, 400);
      browser.setUrl("http://www.google.com");
      shell.open();
      while (!shell.isDisposed() && f.isVisible()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
      display.dispose();
      f.dispose();
   }
}

I found the former solution at a german webpage: http://www.java-forum.org/awt-swing-javafx-swt/66264-swt-browser-swing.html

If you can use JavaFX, you can create a simple Browser (WebKit based) following this tutorial: http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm