Fuzio in SWT

The easiest way to use Fuzio in an SWT Gradle project is to clone our pre-configured Gitee repository, where everything is set up and ready to run.

Prerequisites 

Getting the project 

Clone the Gitee repository using the following command:

git clone https://gitee.com/jiku-technology-dev/fuzio-quickstart-gradle-swt.git
cd fuzio-quickstart-gradle-swt

Run the SWT application 

Use the following command to build and run the SWT application:

./gradlew run -Dfuzio.license.key=<your_license_key>

Once launched, you will see an SWT application with a BrowserView component displaying https://html5test.jiku.co:

BrowserView in SWT app

Project overview 

This section describes how to configure the Gradle project to include Fuzio, and how to embed the Fuzio BrowserView component into an SWT shell to display loaded web content.

Configuring the Gradle project 

The Gradle project uses the Fuzio Gradle plugin to add the required Fuzio dependencies, fetch the Chromium binaries for the current platform, and pull in the platform-specific SWT dependencies.

Here is how the build.gradle.kts file is configured:

import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.taskdefs.condition.Os.FAMILY_MAC

plugins {
    java
    application
    kotlin("jvm") version "2.0.0"

    // Adds Fuzio dependencies.
    id("tech.fuzio.gradle") version "1.0.0"
}

repositories {
    mavenCentral()
}

fuzio {
    // Use the latest stable Fuzio version.
    version = "2026.3.0"
}

dependencies {
    // Detects the current platform and adds the corresponding Chromium binaries.
    implementation(fuzio.currentPlatform)

    // Adds a dependency on the SWT UI toolkit integration.
    implementation(fuzio.swt)

    // Adds a dependency on the Fuzio Kotlin DSL.
    implementation(fuzio.kotlin)

    // Adds the SWT dependency for the current platform.
    implementation(Swt.toolkitDependency)
}

// Registers the dependency substitution required to use SWT with Gradle.
Swt.configurePlatformDependency(project)

application {
    // Define the main class for the Java application.
    mainClass.set("tech.fuzio.quickstart.gradle.swt.App")

    // Alternatively, you can run the Kotlin example:
    // mainClass.set("tech.fuzio.quickstart.gradle.swt.AppKt")
}

tasks.withType<JavaExec> {
    if (Os.isFamily(FAMILY_MAC)) {
        jvmArgs(
            // Required to run SWT under Cocoa on macOS.
            "-XstartOnFirstThread"
        )
    }

    // Assign all Java system properties from the command line
    // to the JavaExec task in order to pass the Fuzio license key.
    systemProperties(System.getProperties().mapKeys { it.key as String })
}

Embedding Fuzio into SWT 

There are two SWT app implementations in the project: Java and Kotlin.

Both implementations are similar and demonstrate how to:

  1. Initialize an Engine (Chromium) instance.
  2. Create a Browser instance.
  3. Load the required web page.
  4. Embed a BrowserView component into an SWT shell to display the loaded web page:
Java
Kotlin
import static tech.fuzio.engine.RenderingMode.HARDWARE_ACCELERATED;

import tech.fuzio.engine.Engine;
import tech.fuzio.view.swt.BrowserView;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public final class App {

    public static void main(String[] args) {
        // Initialize Chromium.
        var engine = Engine.newInstance(HARDWARE_ACCELERATED);

        // Create a Browser instance.
        var browser = engine.newBrowser();

        // Load the required web page.
        browser.navigation().loadUrl("https://html5test.jiku.co");

        var display = new Display();
        var shell = new Shell(display);
        shell.setText("Fuzio SWT");
        shell.setLayout(new FillLayout());

        // Create and embed SWT BrowserView widget to display web content.
        var view = BrowserView.newInstance(shell, browser);
        view.setSize(1280, 800);

        shell.pack();
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        // Shutdown Chromium and release allocated resources.
        engine.close();

        display.dispose();
    }
}
import tech.fuzio.dsl.Engine
import tech.fuzio.engine.RenderingMode.HARDWARE_ACCELERATED
import tech.fuzio.view.swt.BrowserView
import org.eclipse.swt.layout.FillLayout
import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Shell

fun main() {
    // Initialize Chromium.
    val engine = Engine(HARDWARE_ACCELERATED)

    // Create a Browser instance.
    val browser = engine.newBrowser()

    // Load the required web page.
    browser.navigation().loadUrl("https://html5test.jiku.co")

    val display = Display()
    val shell = Shell(display)
    shell.text = "Fuzio SWT"
    shell.layout = FillLayout()

    // Create and embed SWT BrowserView widget to display web content.
    val view = BrowserView.newInstance(shell, browser)
    view.setSize(1280, 800)

    shell.pack()
    shell.open()

    while (!shell.isDisposed) {
        if (!display.readAndDispatch()) {
            display.sleep()
        }
    }
    // Shutdown Chromium and release allocated resources.
    engine.close()

    display.dispose()
}

What’s next 

Customer Support

QR code to follow us on WeChat

Technical Support

QR code to follow us on WeChat