Reference
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 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 AppContext, so two users do not share static state, focus, clipboard, or drag-and-drop status.
SwingBridge Component
The SwingBridge class is the entry point. It is a Vaadin Flow 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 SwingBridgeRunner’s helpers to load JARs from a `swing-app-jar-list.conf file or a custom location.
Lifecycle Hooks
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 createClassLoaderSupplier(), which subclasses also override (see Constructor Variants).
SwingBridgeRunner Helpers
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 |
| Launch the Swing application in an isolated |
| Read a |
| Read every |
| Build a |