SWT Browser Widget with Mozilla (SWT.MOZILLA)
We can use browser inside our java application with SWT browser widget. We can load external HTML pages or websites into our applications using it.
Normal way to initialize browser widget in your application is following.
Browser browser = new Browser(shell, SWT.NONE);
This will create a widget with OS specific browser instance. If you are in windows, Internet Explorer will be your browser host. For Linux default is Mozilla. Personally I don’t like IE much. And there’s a way to load Mozilla to SWT browser widget. Other than that there’s another advantage with using Mozilla, By using Mozilla if you right click nothing will happen inside the application. With IE, users can detect we are using HTML page inside the application. That’s by right click will show the browser specific context menu. Other than that using Mozilla we can get powerful features from Mozilla and XUL runner runtime. Powerful feature with browser widget is we can call JavaScript functions from Java as well as java functions from JavaScript.
There are few steps you have to achieve this goal.
-
Download and install XUL runner.
- I’ve downloaded the SDK version. This includes runtime version and additional files needed for development purposes.
http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.2/sdk/
- Installation instructions can be found at following
https://developer.mozilla.org/en/XULRunner_1.9.1_Release_Notes
- It mentioned to run following command in order to install XUL Runner.
xulrunner.exe –register-global
- But we can’t see anything happening. Actually it’s registering some variables in windows registry. Run regedit and see whether following variables are set in your registry.
- HKEY_LOCAL_MACHINE/Software/mozilla.org/GRE (for register global)
- HKEY_CURRENT_USER/Software/mozilla.org/GRE (for register user)
- https://developer.mozilla.org/en/GRE_Registration
- I’ve downloaded the SDK version. This includes runtime version and additional files needed for development purposes.
- Now you can start with Development of SWT Browser application.
Just change SWT.NONE to SWT.MOZILLA to load Mozilla into the widget.