Creating and using a WebRenderer browser instance







The two most important parts of the WebRenderer API are class BrowserFactory and interface IBrowserCanvas.


BrowserFactory is used to set up WebRenderer's licensing information and global settings, and to spawn browser instances once setup is complete. Several of these settings control how WebRenderer searches for the library files it needs.

Key methods for configuring BrowserFactory's library search behaviour are:

  • setLibraryPath(String path)
  • setLibraryPath(File path)
  • setMozillaPath(String path)
  • setMozillaPath(File path)
  • setHomeDirectory(String path)
  • setHomeDirectory(File path)

If the WebRenderer JAR files are not in the CLASSPATH the library path must be set to the location of the WebRenderer libraries, specifically the webrenderer-swing-xxx32.jar (xxx denotes the platform prefix such as windows, solaris, linux, osx, aix) and the corecomponents-swing-xxx32.jar. The webrenderer-swing-xxx32.jar and corecomponents-swing-xxx32.jar can be placed in different directories but if the corecomponents-swing-xxx32.jar are in a different directory the setMozillaPath and setLibraryPath methods must be called to point WebRenderer to their respective location.

WebRenderer library search order (searching stops when libraries are found)
setLibraryPath/setMozillaPath, then Java CLASSPATH then current directory, then user home directory

The webrenderer-swing.jar must always be in the Java CLASSPATH. For example:

java -cp webrenderer-swing.jar;. TestBrowser
Linux, Mac OS X, Solaris and AIX
java -cp webrenderer-swing.jar:. TestBrowser

setLicenseData(String username, String serial)

The setLicenseData method is essential to receive full WebRenderer functionality. This method must be called before a browser is spawned. If the license information is not set a dialog will display notifying you and some WebRenderer functionality will be disabled.



The WebRenderer loadURL method is core to loading pages into WebRenderer. The loadURL method can take a URL as a Java String or a java.net.URL .


WebRenderer's loadHTML is the mechanism used to load HTML and web content into WebRenderer through Java Strings, InputStreams or byte arrays.

Example usage:

browser.loadHTML("<HTML><B>Hello World</B></HTML>", "");

If an empty base reference is passed to the loadHTML method then the base directory will be the directory the application is loaded from. If there are relative references to images, javascript, css etc WebRenderer will search for these in the base reference. The base reference can be a remote URL, it does not necessarily have to be on a local disk. If the base reference is set to a remote URL then WebRenderer will load the resources relative from the passed URL as requested by the document loaded.


When adding an IBrowserCanvas to a JPanel or equivalent a Component must first be obtained from it. This can be achieved by calling:


After the component is obtained it can be added to a graphical layout.


The setProxy method allows the browser to connect to web sites via a proxy server. This can be an authenticated proxy. For the proxy settings to take the method enableProxy must also be called on the IBrowserCanvas instance. Use of the proxy can be disabled via the disableProxy method.









Copyright JadeLiquid Software - www.jadeliquid.com