> Markdown version of [Reference](https://vaadin.com/docs/next/tools/modernization-toolkit/swing-bridge/reference). Section index: [llms.txt](https://vaadin.com/docs/next/tools/llms.txt)

# <a id="swing-bridge.reference"></a>Reference

This page summarizes the public Java API surface of SwingBridge and points at the skeleton starter project.

## <a id="swing-bridge.reference.under-the-hood"></a>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.

## <a id="swing-bridge.reference.swingbridge"></a>`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.

### <a id="swing-bridge.reference.swingbridge.constructors"></a>Constructors

```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.

### <a id="swing-bridge.reference.swingbridge.hooks"></a>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                                                                                                                                                                                                                                 |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `beforeInit(Component component)` | After the Swing application has launched and produced a visible `JFrame`, but before SwingBridge wires that frame into its canvas. Useful for last-minute configuration of the Swing component itself (sizing, native look-and-feel tweaks). |
| `afterInit(Component component)`  | 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](https://vaadin.com/docs/next/tools/modernization-toolkit/swing-bridge/adding-your-app.md#swing-bridge.adding-your-app.constructors)).

## <a id="swing-bridge.reference.swingbridge-runner"></a>`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                                                                                                                                                                                         |
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `createSession(String mainClassFQN)`                     | Create a `SwingBridgeSession` that ties the Vaadin session to a specific main class. Pass it to `runSwingApp(…​)`.                                                                          |
| `runSwingApp(SwingBridgeSession, …)`                     | Launch the Swing application in an isolated `AppContext`. Returns a `CompletableFuture<JFrame>` that resolves when the first window appears (or completes exceptionally on launch failure). |
| `loadSwingAppJarList()`                                  | Read a `swing-app-jar-list.conf` from the classpath root and return the JAR paths it lists. Combine with `createClassLoader(…​)`.                                                           |
| `loadJarsFromDirectory()`                                | Read every `.jar` in the configured `applibs` directory.                                                                                                                                    |
| `createClassLoader(List<Path> jars, ClassLoader parent)` | Build a `URLClassLoader` from the supplied JAR paths.                                                                                                                                       |

## <a id="swing-bridge.reference.next-steps"></a>Next Steps

- [Configuration](https://vaadin.com/docs/next/tools/modernization-toolkit/swing-bridge/configuration.md#swing-bridge.configuration) for the system properties that control this behavior at deployment level.
