Secondary Windows
When your Swing application opens a second top-level window on top of its main frame, SwingBridge surfaces that window in the browser as a Vaadin overlay. This applies to JDialog, JFrame, and JWindow. Popups, menus, and tooltips are handled separately and are always non-modal.
This page explains how the modality of a secondary window is decided, and how to control it for a JFrame.
How Modality Is Decided
Whether a secondary window is rendered modal (it blocks interaction with everything behind it) or modeless (the rest of the UI stays interactive) depends on the window type:
| Window type | Modality |
|---|---|
| Follows the dialog’s own modality — the value of its |
| Modeless by default. A |
Controlling JFrame Modality
Some applications implement a secondary dialog as a JFrame rather than a JDialog, and still expect it to block the main frame. Because a JFrame has no modality property of its own, SwingBridge cannot infer this. Declare it explicitly by attaching a client-property hint to the frame’s root pane before the frame becomes visible.
Add the swing-bridge-annotations dependency to the module that builds your Swing application:
Source code
XML
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>swing-bridge-annotations</artifactId>
<version>${swing-bridge.version}</version>
</dependency>Then set the WindowHints.MODALITY client property to MODAL:
Source code
Java
import com.vaadin.swingbridge.window.WindowHints;
JFrame frame = new JFrame("Edit Customer");
// ... build the frame's content ...
// Render this frame as a modal overlay in SwingBridge.
frame.getRootPane().putClientProperty(WindowHints.MODALITY,
WindowHints.Modality.MODAL);
frame.setVisible(true);The hint travels with the window itself, so it takes effect no matter which Vaadin route or SwingBridge instance renders the frame — you set it once, in your Swing code, at the point where the frame is shown.
|
Note
|
Set the hint before the frame becomes visible. SwingBridge reads it when it first surfaces the window, so changing it after the frame is shown has no effect. |
To be explicit about a frame that should stay modeless, use WindowHints.Modality.MODELESS. Any window without the hint is already modeless, so this is only needed for readability.
|
Tip
|
This hint has no effect on a |
Behavior Change
Earlier versions of SwingBridge rendered every secondary JFrame as modal. Secondary frames are now modeless by default. If your application relied on a JFrame blocking the main frame, add the WindowHints.MODALITY hint shown above to restore that behavior.
Next Steps
-
Public API surface and lifecycle hooks: Reference.
-
Call into Swing code and listen to Swing events from Vaadin: Interoperability.