SWT
The Standard Widget Toolkit (SWT) is a Java GUI toolkit that uses each platform’s native UI widgets to build desktop applications. In other words, SWT programs call the operating system’s own buttons, menus, windows and other controls, which makes Java apps look and feel just like regular desktop software.
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
in recent versions). You use it 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 is a Chromium-based widget that embeds as an SWT Control. Because it uses Chromium under the hood (via the Chromium Embedded Framework), the Browser shows modern web content reliably and with good performance, without any extra work on your part.
That means you can place it in your layouts or composite containers and handle events normally, just like a button or text field. Once created, you can call methods like browser.setUrl("https://…")
or load HTML snippets, and the Equo Chromium engine will render the page.
To use Equo Chromium with the SWT toolkit, follow these steps:
You may encounter duplicate class names ( |
1. Add the Browser Import
Start by adding the Equo Chromium SWT Browser class to your Java file:
import com.equo.chromium.swt.Browser;
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 |
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 |