This tutorial demonstrates how to integrate existing Java Swing applications into webforJ web applications using the WebswingConnector
component.
The project consists of two applications:
- Swing Application (
webforj-swing-app
) - A traditional Java Swing customer management table - webforJ Application (
webforj-webswing-integration
) - A web app that embeds the Swing app
This architecture enables progressive modernization: embed your existing Swing apps today, then gradually replace them with webforJ components over time.
- Java 21+
- Maven 3.9+
- Webswing Server (for running the Swing app in web mode)
cd webforj-swing-app
mvn clean package
# Creates custom-table-app.jar
The Swing app automatically detects if it's running under Webswing and adapts its behavior:
- Standalone mode: Shows standard Swing dialogs for editing
- Webswing mode: Communicates with the webforJ wrapper via events
Copy custom-table-app.jar
to your Webswing deployment and configure it to be accessible at:
http://localhost:8080/custom-table-app/
cd webforj-webswing-integration
mvn spring-boot:run
Open http://localhost:8090 to see the integrated application.
The WebswingConnector
embeds Webswing-hosted applications directly in your webforJ app:
@Route("/")
public class CustomerTableView extends Composite<FlexLayout> {
public CustomerTableView(@Value("${webswing.connector.url}") String webswingUrl) {
WebswingConnector connector = new WebswingConnector(webswingUrl);
connector.setSize("100vw", "100vh");
// Handle events from Swing app
connector.onAction(event -> {
if ("select-customer".equals(event.getActionName())) {
// Show webforJ dialog for editing
}
});
self.add(connector);
}
}
Swing → webforJ: The Swing app sends events using Webswing API:
if (isWebswing) {
api.sendActionEvent("select-customer", gson.toJson(customer), null);
}
webforJ → Swing: The webforJ app sends commands back:
connector.performAction("update-customer", gson.toJson(customer));
Configure the Webswing URL in application.properties
:
# Webswing connector configuration
webswing.connector.url=http://localhost:8080/custom-table-app/
# Server configuration
server.port=8090
This integration pattern provides:
- Zero modification deployment - Run existing Swing apps in the browser immediately
- Progressive modernization - Replace Swing components with webforJ gradually
- Hybrid applications - Combine web UI with specialized desktop functionality
- Investment protection - Preserve years of business logic development