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 (
custom-table-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 custom-table-app
mvn clean package
# Creates custom-table-app.jarThe 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
Use your Webswing admin console at http://localhost:8080/admin to add and configure your swing app.
In the admin console, configure:
- Application Name: becomes part of the URL path (e.g.,
custom-table-app→http://localhost:8080/custom-table-app/) - Main Class: the entry point of your Swing app
- Classpath: path to your app JAR and dependencies
- JVM Arguments: memory settings, system properties, and other JVM options
- Home Directory: working directory for the app
Note: Make sure to move your previously built custom-table-app.jar to the folder you set as your classpath.
After configuration, your Swing app will be accessible at http://localhost:8080/custom-table-app/
cd webforj-webswing-integration
mvn spring-boot:runOpen 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=8090This 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