Published: 03/22/10 12:51 PM
The excellent library DJ Native Swing allows a java-program to use an embedded native Browser (among other things).
On Windows-Systems it uses an Internet-Explorer per default. However this browser isn’t exactly known for being standards-compliant. In order to use a mozilla firefox / gecko-browser, you can use XulRunner.
In order to bundle the XulRunner with your application (thus run a certain version without the need to install xulrunner), you can set the following properties in your java-application:
String xulHome = new File("lib/xulrunner").getAbsolutePath(); NSSystemPropertySWT.WEBBROWSER_XULRUNNER_HOME.set(xulHome); System.setProperty("org.eclipse.swt.browser.XULRunnerPath", xulHome); |
This code needs to have the following directory-structure:
- yourapp.jar
- lib (directory)
- xulrunner (directory)
- xulrunner-files (e.g. xpcom.dll)
- xulrunner (directory)
A complete example on how to set up a frame with a browser can be found in the example source code of DJ Native Swing.
[Update]
You can’t expect that a native application embedded in swing will completely behave like a swing component.
There are several issues. Some of them have been solved by the developers of DJ Native Swing. Some not.
Currently you cannot display a Browser in a translucent (semitransparent) or shaped window.
There’s a good collection of thoughts and tests about embedding a browser in Netbeans.
And while you search the net for a useable Swing-Webbrowser, you’ll stumble across lots of wanna-be-solutions. All of them have issues concerning the integration in swing or the standards-compliant rendering.
Hey!
Thanks for your post!
I tried it exactly like this but I get:
org.eclipse.swt.SWTError: XPCOM error -2147467261
Do you have any ideas?
thanks!
Sorry!
I just found the solution!
Don’t user xulrunner 2.x!
I use the older one (1.9.x) and now it works!
Thanks for your great blog entry!!
You’re welcome! Thanks for posting not only the problem but also the solution and for your feedback.
Hi Thomas,
Unless I am mistaken, this line is not necessary (set internally by DJ NativeSwing):
System.setProperty(“org.eclipse.swt.browser.XULRunnerPath”, xulHome);
More importantly, there were efforts for NetBeans integration, which are summed up in a NetBeans.txt file that is part of the distribution.
I hope these details will help other users who stumble on your post
Cheers,
-Christopher
Hi Christopher,
thanks for the tips. Is there a link to the Netbeans integration summary? I’d be glad to provide that with the blog-article.
[...] Is it true that this technology is based on the launching of current operational system’s default browser within java application? (http://blog.macrominds.de/2010/03/embedded-gecko-browser-in-java-application-with-djnativeswing/) [...]