SWT

The Standard Widget Toolkit (SWT) is a Java GUI toolkit that uses each platform’s native UI widgets to build desktop applications. The integration between SWT and Equo Chromium is simple. Equo Chromium supplies a special browser control class for SWT (for example, com.equo.chromium.swt.Browser), which you can use just like any other SWT widget: import the class, create a new instance with a parent Composite, and set its URL or HTML content. Under the hood, this Browser control is a Chromium-based widget that embeds as an SWT Control. Because it uses Chromium under the hood through Equo Chromium, the Browser shows modern web content reliably and with good performance.

Once created, you can call methods like browser.setUrl("https://…​") or load HTML snippets, and the Equo Chromium engine will render the page.

Using Equo Chromium with the SWT toolkit

1. Add the Browser class import

Start by adding the Equo Chromium SWT Browser class to your Java file:

import com.equo.chromium.swt.Browser;

You may encounter duplicate class names (OpenWindowListener, WindowEvent) in the com.equo.chromium.swt package. If compilation fails, either adjust your imports or use fully qualified class names.

2. Instantiate your browser

Create a Browser instance inside any SWT Composite. The example below shows how to embed a browser that fills its container and navigates to a specified URL:

public class SinglePagePart {
    public void createBrowser(Composite parent, String url) {
        // Make the browser fill all available space
        Browser browser = new Browser(parent, SWT.NONE);
        browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        // Load the web page
        browser.setUrl(url);
    }
}

Use GridData(SWT.FILL, SWT.FILL, true, true) to ensure the browser resizes with its parent.

3. Set a background color

You can set the parent Composite to have a background color before the browser is created. For example:

Display display = composite.getDisplay();
// Create a bright green background
Color bgColor = new Color(display, 0, 255, 0);
composite.setBackground(bgColor);

// Now create the browser
Browser browser = new Browser(composite, SWT.NONE);

Remember to call bgColor.dispose() when your Composite is disposed to avoid resource leaks.