Fuzio in Swing

The easiest way to use Fuzio in a Swing 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-swing.git
cd fuzio-quickstart-gradle-swing

Run the Swing application 

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

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

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

BrowserView in Swing app

Project overview 

This section describes how to configure the Gradle project to include Fuzio, and how to embed the Fuzio BrowserView component into a Swing frame to display loaded web content.

Configuring the Gradle project 

The Gradle project uses the Fuzio Gradle plugin to add the required Fuzio dependencies and fetch the Chromium binaries for the current platform.

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

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 fetches the corresponding Chromium binaries.
    implementation(fuzio.currentPlatform)

    // Adds a dependency on the Swing UI toolkit integration.
    implementation(fuzio.swing)

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

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

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

tasks.withType<JavaExec> {
    // 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 })
    jvmArgs(
        // Grant access to the java.desktop/java.awt module
        // so that Fuzio can use Swing focus traversal.
        "--add-opens=java.desktop/java.awt=ALL-UNNAMED"
    )
}

Embedding Fuzio into Swing 

There are two Swing 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 web view component into a Swing frame to display the loaded web page:
Java
Kotlin
import static tech.fuzio.engine.RenderingMode.HARDWARE_ACCELERATED;
import static javax.swing.SwingUtilities.invokeLater;

import tech.fuzio.engine.Engine;
import tech.fuzio.view.swing.BrowserView;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;

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();

        invokeLater(() -> {
            var frame = new JFrame("Fuzio Swing");
            frame.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    // Shutdown Chromium and release allocated resources.
                    engine.close();
                }
            });
            // Create and embed Swing BrowserView component to display web content.
            frame.add(BrowserView.newInstance(browser));
            frame.setSize(1280, 800);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);

            // Load the required web page.
            browser.navigation().loadUrl("https://html5test.jiku.co/");
        });
    }
}
import tech.fuzio.dsl.Engine
import tech.fuzio.engine.RenderingMode.HARDWARE_ACCELERATED
import tech.fuzio.view.swing.BrowserView
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.JFrame
import javax.swing.SwingUtilities

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

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

    SwingUtilities.invokeLater {
        JFrame("Fuzio Swing").apply {
            // Shutdown Chromium and release allocated resources when the frame closes.
            addWindowListener(object : WindowAdapter() {
                override fun windowClosing(e: WindowEvent) {
                    engine.close()
                }
            })
            // Create and embed Swing BrowserView component to display web content.
            add(BrowserView.newInstance(browser))
            setSize(1280, 800)
            setLocationRelativeTo(null)
            isVisible = true
        }

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

What’s next 

Customer Support

QR code to follow us on WeChat

Technical Support

QR code to follow us on WeChat