Technology1 min read

Your Swing and JavaFX Code on iPhone, Android and the Web

By · Published by Everything Blog

In short

Codename One converts existing graphical desktop projects into standalone native applications by remapping bytecode to its own implementations and eliminating embedded JVMs. Client devices avoid costly runtime parsing because the compiler converts FXML files directly into Java classes and translates JavaFX CSS into preprocessed tables. Benchmarks demonstrate that the generated native outputs launch up to 5.5 times faster from process start to the first painted frame compared to standard JVM images. However, deployment requires developers to adapt to strict architectural constraints that substitute compile-time code generation for traditional runtime reflection.

Key points

  • Native execution without a bundled JVM significantly accelerates application startup spee…: Native execution without a bundled JVM significantly accelerates application startup speeds across client platforms.
  • Preprocessing graphical markup and style sheets at build time removes client-side XML par…: Preprocessing graphical markup and style sheets at build time removes client-side XML parsing overhead.
  • Developers must replace traditional runtime reflection and standard networking libraries…: Developers must replace traditional runtime reflection and standard networking libraries with build-time code generation techniques.

Sources checked by our analysis pipeline: 1

There’s a lot of Swing and JavaFX code in the world. Much of it is internal tooling and line of business software that works fine and that nobody wants to rewrite. Then someone asks for it on an iPad, or in a browser, and the answer has always been “rewrite it.”

Codename One can now build a large share of that code for iOS, Android, the web and native desktop, as a native app with no JVM inside. SwingSet2 and Notepad, the JDK’s own demos, both build and run. This post shows what carries over, what it costs in size and start-up (less than the JVM), and why the parts that don’t carry over have better replacements in a client app.

What it does

You drop the project’s src/main

into a Codename One project, or import it:

mvn cn1:import-desktop-project -Dcn1.desktop.import=/path/to/MyDesktopApp

Your code keeps compiling against the JDK’s own Swing, or against our JavaFX API under the real javafx.*

names. A remap step after javac points the bytecode at our implementations of java.awt

, javax.swing

, java.beans

, javax.imageio

, a…

Technology