Add-on Directory

JavaFX Extension for Vaadin SwingBridge - Vaadin Add-on Directory

JavaFX extension for SwingBridge JavaFX Extension for Vaadin SwingBridge - Vaadin Add-on Directory
Run your existing JavaFX application in the browser as part of a Vaadin Flow application, without rewriting it. This extension brings JavaFX support to [Vaadin SwingBridge](https://vaadin.com/docs/latest/tools/modernization-toolkit/swing-bridge). Embed your JavaFX application in a Vaadin view using a single component, while keeping your existing application code intact. Each user gets a separate application instance running on the server. It's a practical solution for bringing established JavaFX applications to the web without committing to a full rewrite. Users can access the application through a browser, while you gradually replace JavaFX screens with native Vaadin views. Vaadin views and the JavaFX application can communicate in both directions, allowing you to modernize your application one screen at a time. **Requirements:** This extension builds on Vaadin SwingBridge and requires a SwingBridge license. ### Features - **Run JavaFX in the browser:** Embed an existing JavaFX application in a Vaadin Flow view. - **Isolated user sessions:** Each user gets a separate JavaFX application instance running on the server. - **Bidirectional communication:** Call methods between Vaadin views and the JavaFX application using SwingBridge annotations and generated interfaces. - **Gradual modernization:** Replace JavaFX screens with Vaadin views incrementally, without rewriting the entire application. ### Getting Started The [starter project](https://github.com/vaadin-component-factory/skeleton-starter-vaadin-swing-bridge-javafx) provides a ready-to-run Vaadin application with an embedded JavaFX example. Clone the repository and start the application: ```bash git clone https://github.com/vaadin-component-factory/skeleton-starter-vaadin-swing-bridge-javafx.git cd skeleton-starter-vaadin-swing-bridge-javafx ./mvnw # Use mvnw.cmd on Windows ``` Open http://localhost:8888 and sign in with `admin` / `admin`. ### Embed Your JavaFX Application 1. Place your application's JAR files in the `applibs/` directory. Do not include JavaFX libraries. 2. Add the `JavaFXBridge` component to a Vaadin view. The application shell must have `@Push` enabled. ```java @Route("") public class MyAppView extends VerticalLayout { public MyAppView() { setSizeFull(); JavaFXBridge app = new JavaFXBridge("com.example.MyApp"); add(app); expand(app); } } ``` 3. Run the application. The starter project's `pom.xml` includes the required dependencies and JVM flags. ### Communication Between Vaadin and JavaFX The extension uses SwingBridge's interoperability features to let Vaadin views and JavaFX applications call each other's methods. **Call JavaFX methods from Vaadin** Annotate the methods you want to expose in your JavaFX application: ```java public class CustomersApp extends Application { private static CustomersApp current; @InstanceProvider public static CustomersApp current() { return current; } @Override public void start(Stage stage) { current = this; /* ... */ } @ExposedMethod public void showCustomer(String id) { /* ... */ } } ``` SwingBridge's `swing-bridge-codegen-maven-plugin` generates a type-safe interface from the JAR files in `applibs/`. Use the generated interface to call JavaFX methods from your Vaadin views: ```java JavaFXBridge.interop("com.example.CustomersApp") .of(CustomersAppBridge.class) .onReady(app -> app.showCustomer(id)); ``` **Call Vaadin methods from JavaFX** JavaFX event listeners can also invoke methods in Vaadin views annotated with `@VaadinCallback`, enabling communication in both directions. ### Learn More - [WarehousePro JavaFX Demo](https://github.com/onuridrisoglu/javafx-bridge-demo) — See a JavaFX desktop application running in the browser, communicating with Vaadin views, and being modernized screen by screen. - [Add-on README](https://github.com/vaadin-component-factory/swing-bridge-javafx-addon#readme) — Detailed configuration instructions, JVM flags, interoperability examples, and known limitations. - [Vaadin SwingBridge Documentation](https://vaadin.com/docs/latest/tools/modernization-toolkit/swing-bridge) — Learn more about SwingBridge and its modernization capabilities. ### Sponsored Development Major pieces of development of this add-on has been sponsored by multiple customers of Vaadin. Read more about Expert on Demand at: [Support](https://vaadin.com/support) and [Pricing](https://vaadin.com/pricing)

JavaFX Extension for Vaadin SwingBridge version 1.0.0-alpha1

JavaFX Extension for Vaadin SwingBridge version 1.0.0-alpha2