Reference
- What Happens Under the Hood
SwingBridgeComponentSwingBridgeRunnerHelpers- Sample Project
- Next Steps
This page summarizes the public Java API surface of SwingBridge and points at the skeleton starter project.
What Happens Under the Hood
Once you’ve set up your [classname]`SwingBridge` subclass (or instance), the framework handles:
-
Launching your Swing application in the background when the component attaches.
-
Capturing the UI as images and streaming the changed regions to the browser.
-
Routing user interactions — clicks, keyboard input, window resizing — back into the AWT event queue.
-
Managing dialogs, popups, and tooltips that your Swing application creates.
-
Updating the display continuously so users see a live view of your application.
Every browser session runs the Swing application inside its own isolated [classname]`AppContext`, so two users do not share static state, focus, clipboard, or drag-and-drop status.
SwingBridge Component
The `[classname]`SwingBridge class is the entry point. It is a Vaadin Flow `[classname]`Div that, on attach, launches the Swing application and renders it into the page.
Constructors
Source code
Java
new SwingBridge(String mainClassFQN);
new SwingBridge(String mainClassFQN, String[] args);
new SwingBridge(String mainClassFQN, Supplier<URLClassLoader> classLoaderSupplier);The first form uses the default classloader supplier (loads JARs from the applibs/ directory). The second forwards the given arguments to the Swing application’s main method. The third hands full control of classloader construction to the caller — pair it with [classname]`SwingBridgeRunner`’s helpers to load JARs from a `swing-app-jar-list.conf file or a custom location.
Lifecycle Hooks
[classname]`SwingBridge` exposes two protected hooks. Override them in a subclass to run custom code before or after the Swing application is wired into the view.
| Hook | When it runs |
|---|---|
| After the Swing application has launched and produced a visible |
| After SwingBridge has wired the frame into its canvas and frame updates are ready to flow. Useful for hooking up listeners on the Swing component or signalling readiness to the rest of the Vaadin view. |
A custom classloader supplier is contributed via [methodname]`createClassLoaderSupplier()`, which subclasses also override (see Constructor Variants).
SwingBridgeRunner Helpers
[classname]`SwingBridgeRunner` is a static utility used by the component itself, but several of its methods are public and useful when you build a custom classloader supplier.
| Method | Use |
|---|---|
| Create a `[classname]`SwingBridgeSession |
| Launch the Swing application in an isolated `[classname]`AppContext |
| Read a |
| Read every |
| Build a |
Sample Project
The skeleton starter is the recommended starting point. It is a working SwingBridge project — Maven configuration, JVM flags, and a Vaadin view wired up — that you can clone and adapt to your own Swing application by replacing the JARs in applibs/. See Getting Started for the walkthrough.
Next Steps
-
Bring in your own Swing JAR and wire up a Vaadin view: Adding Your Swing Application.
-
Tune runtime behaviour: Configuration.
-
Diagnose launch failures: Troubleshooting.