Friday, March 18, 2016

Which GUI API is best for Desktop Java Applications?

When programming in Java there are many different GUI APIs to choose from including AWT, SWT, Swing, and JavaFX. Which one should you use for your Java application? Is it even worth learning how to use these libraries considering how most Java development is now Android based?

Is it worth learning any of these APIs?

These days the vast majority of Java development is used to create Android apps. The majority of consumer and business oriented desktop software is not written in Java. Other languages like C#, C++, and Swing have taken the lead. Still, Java is useful for writing cross-platform apps which run across all the operating systems. Occasionally, new Java based desktop applications still pop up such as Minecraft. Eclipse, Deluge, and Netbeans are also written in Java. Many legacy business applications and specialized tools still exist which have been built using these APIs.

There is definitely still value in learning how to build GUI desktop applications in Java - even if only for the sake of learning how GUIs work. Most of the APIs can be learned with relative ease, and investing some time into learning how they work is still beneficial.

Which to learn?

We can begin by eliminating one library entirely - AWT, or Abstract Window Toolkit, which was introduced much earlier than the other APIs, and is essentially on its last legs as far as desktop development is concerned.

Swing, which first appeared in the 90s, is also relatively old at this point. Still, you're more likely to find Swing based applications floating around than AWT simply because it's a younger API than AWT. Like AWT, I would not recommend spending a lot of time learning Swing simply because of age and lack of continued updates. It is currently being phased out to be replaced by JavaFX.

This leaves two remaining options for your GUI development purposes in Java: JavaFX and SWT. JavaFX was an attempt by Oracle to modernize GUI development. It works well, and there's even a Scene Builder tool to make development easy. Unfortunately it appears that JavaFX has not been updated since 2014 - so continued support may be spotty.

Finally, there is SWT, which stands for Standard Widget Toolkit. SWT is maintained by the Eclipse foundation and has been updated as of 2015. Like JavaFX's Scene Builder, there is a tool available for SWT called WindowBuilder. Personally I prefer WindowBuilder to Scene Builder because it's generally easier to use and integrates well into the Eclipse IDE. You can also use WindowBuilder to create Swing applications - but SWT is more modern and has more features so you might as well go with SWT.

In conclusion, SWT is the most recently updated GUI building API and the one I recommend. If I had to order them by which ones to learn - I would probably do it like this:

  1. SWT because it still appears to be maintained and the WindowBuilder integrates well with Eclipse
  2. Swing because it is still used in many legacy applications and also is supported by WindowBuilder
  3. JavaFX because it may be updated in the future and the SceneBuilder is a relatively powerful tool with decent Netbeans integration
  4. AWT because it is the oldest of the options presented here and is likely the least used out of the four


Post a Comment