Java Swing UI on iPad, iPhone and Android

Swing on iPad with AjaxSwing Apple is selling iPhones and iPad as fast as they can make it. In Q4 of 2011 iPad outsold PCs for the first time in history. And while PC market is struggling to show any signs of growth, the mobile devices market is growing at 25-35% annually with no signs of a slowdown. Unless you were living under a rock, you know that modern applications have to support iOS devices as well as other mobile platforms such as Android and Windows Phone. Web applications, being the linga franca of the internet, will run on any device with a browser. But what about Java desktop applications written in Swing?

Best option would be to wait for Apple to release Java on iPad, but as Steve Jobs' infamous quote goes "Java's not worth building in. Nobody uses Java anymore. It's this big heavyweight ball and chain." So you can't count on having a JVM on iOS devices, WebStart is not coming to mobile devices, and if you have Swing desktop application or applet your only option if to rewrite it in Objective C and re-design UI in HTML. If you have a decent size codebase, rewriting application can be a very big and expensive undertaking. If you already spent years developing your application, would you want spending them again, getting new bugs and all this just to support new platform? Obviously that doesn't sound like the best solution, so let's try to find a way to run Java on iPad with minimal effort.

Option 1. Rewrite UI in GWT

First option that comes to mind is rebuilding UI with GWT. GWT is a breakthrough technology from Google that allows development of the entire application in pure Java. The user interface is built using Swing-like components and simple layouts, and then it is compiled into a JavaScript executable file that is embedded in HTML page. During the construction the developer only deals with Java, and there is simulated mode that allows testing without doing the full compilation. GWT implements most of the core Java APIs and there is a fairly straightforward way of invoking Java services from the user interface. GWT takes care of browser compatibility and optimizations by producing different compiled versions of the application for different browsers. So you can use GWT and run application in iPad browser, GWT is already a mature and powerful platform, and you don't need to rewrite your code completely, just rebuild your UI with GWT and apply some other changes to source code where needed. Using GWT is a good solution, but it still force you to rebuild some parts, design new UI, retest it, get new bugs with it, fix them in several iterations etc. It would be great if we could use same Swing UI that was already tested and used for several years.

GWT table component demo in Firefox:
GWT Table

Option 2. Automatically convert UI to HTML with AjaxSwing

Running in browser seems like a good option, but it would be nice to be able to leverage the existing Swing codebase. Luckily, there's an app for that. AjaxSwing allows you to convert any java Swing application to a web application so you can then run it on iOS and Android devices. You simply deploy your application to a web server running AjaxSwing and access it directly with web browser. Nothing needs to be installed on client devices because AjaxSwing produces pure HTML and JavaScript UI at runtime.

Let's try to compare AjaxSwing and GWT:
Criteria GWT AjaxSwing
Pure Java (no HTML/JavaScript/XML) Yes Yes
Compilable (runtime type checking, refactoring, early error detection) Yes Yes
Requires JRE on the client No No
Access to all Java APIs in the client code No Yes
UI frameworkCustom Swing
Ability to run on mobile devices Yes Yes
High scalability Yes No
Community Support High Medium
License Apache 2.0Commercial

AjaxSwing uses a 3 steps approach for converting:
  1. Take working desktop application
  2. Copy files to the web server
  3. Open application in a browser
Looks pretty easy? You can take a look at video showing how to use AjaxSwing to convert SwingSet2 application in less than 2 minutes. How much time would it take to rewrite even simple application like SwingSet2 on ObjectiveC or even GWT?

SwingSet2 application in Firefox using AjaxSwing:
SwingSet2 AjaxSwing

Let's take a look at advantages of using AjaxSwing that we found: Of course every solution has tradeoffs, here are some of them: One advantage that we didn't list here, but still noticed while using demo's, AjaxSwing application looks much better then Swing application with most of the themes, of course you can make your Swing application look as you want, but in AjaxSwing even with default theme your application would look nice. Default theme looks nice even on our iPhone and iPad devices.
Below is a screenshot of SwingSet2 running natively on a JVM. Compare it to previous screenshot made from AjaxSwing deployment:
SwingSet2 Swing

AjaxSwing seems to be a mature product with first version dating back to November 1999. The home page is showing a number of prominent clients including Symantec, Nokia and Bertelsmann. If you are a company or a developer, having Swing application, and willing to release it for iPhone and iPad, you should try AjaxSwing as an alternative to rebuilding your application.

You can open AjaxSwing demo directly from your iPhone, iPad or Android device and check it out yourself.