Fuzio in Swing

This page describes how to configure a Gradle project to use Fuzio with the Swing GUI toolkit.

Prerequisites 

Getting the project 

The sample project described below in this guide can be found as the standalone repository on Gitee.

Configuring the Gradle project 

Repository 

Fuzio is distributed via the maven repository hosted by Jiku. Please add the following repository reference to your build.gradle.kts:

repositories {
   // The repository with Fuzio binaries.
   maven("https://jiku.mycloudrepo.io/public/repositories/releases")
}

Version variable 

We recommend to define a variable for the version of Fuzio used in the project. The following sections reference such a variable.

val fuzioVersion = "2026.1.0"

Platform 

To add Fuzio library that works on Windows, macOS, and Linux, please add the following code:

dependencies {
   implementation("tech.fuzio:fuzio-cross-platform:$fuzioVersion")
}

Swing 

To use Fuzio in the Swing GUI of your app, please add the corresponding Fuzio dependencies as well:

dependencies {
   implementation("tech.fuzio:fuzio-swing:$fuzioVersion")
}

Kotlin DSL 

If you develop using Kotlin, then we recommend that you to add Fuzio Kotlin DSL for the best experience.

dependencies {
   implementation("tech.fuzio:fuzio-kotlin:$fuzioVersion")
}

Summary 

As the result, you should have the following build.gradle.kts:


plugins {
    java
    application
    id("org.openjfx.javafxplugin") version "0.1.0"
    kotlin("jvm") version "2.0.0"
}

val fuzioVersion = "2026.1.0"

repositories {
    mavenCentral()
    maven("https://jiku.mycloudrepo.io/public/repositories/releases")
}

dependencies {
    implementation("tech.fuzio:fuzio-cross-platform:${fuzioVersion}")
    implementation("tech.fuzio:fuzio-swing:${fuzioVersion}")
    implementation(kotlin("stdlib-jdk8"))
    implementation("tech.fuzio:fuzio-kotlin:${fuzioVersion}")
}

kotlin {
    jvmToolchain(17)
}

application {
    // Define the main class for the application.
    mainClass.set("SwingApp")

    // Alternatively, you can run a Kotlin example, as follows:
    // mainClass.set("KotlinSwingAppKt")
}

tasks.withType<JavaExec> {
    // Assign all Java system properties from
    // the command line to the JavaExec task.
    systemProperties(System.getProperties().mapKeys { it.key as String })
}

Embedding Fuzio into Swing 

Here are two sample Swing app implementations for 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
// SwingApp.java:

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 SwingApp {

    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/");
        });
    }
}
// KotlinSwingApp.kt:

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/")
    }
}

Run the Swing application 

Use the following command to build and run 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

What’s next 

Customer Support

QR code to follow us on WeChat

Technical Support

QR code to follow us on WeChat