This article reviews the most important GUI Libraries/Frameworks in Java.
Once you’ve graduated from creating simple console based applications, programs which graphical user interfaces (or GUI) are the next step. Java has several GUI libraries or “frameworks” which provide support for creating modern and feature rich user interfaces.
Bear in mind that there are actually almost 10 different (including variants) GUI frameworks in Java. However, we will only be discussing the three most important and well known frameworks in this article. The name of these three frameworks are listed below:
The goal of this article is to do a basic review on these three and explain which one of them is the best choice for someone looking to begin GUI development in Java. We’ll be starting with the oldest (AWT) and end with the newest (JavaFX).
AWT or Abstract Window Toolkit provides interface for Java Programmers to create GUI’s. It’s the oldest Java GUI framework, and thus also the most mature, documented having been tested and tried thoroughly.
AWT has sort of become a legacy framework by now and it’s use is negligible compared to other GUI libraries like Swing and JavaFX. It’s is rather outdated and lacking in advanced components that modern GUI’s of today require. If you wish to create a rich user interface, AWT is not the best option. However, it’s still a suitable choice for smaller and simple GUI interfaces.
AWT has a pretty strong legacy, as the Swing framework is actually based off AWT. There is also the SWT GUI framework which has strong roots in AWT. For these reasons, it’s relatively easy for an AWT user to switch over to Swing. Despite all this though, AWT is a GUI framework better left as a legacy.
Bonus fact: Sometimes (rarely) while working with Swing or JavaFX you will find yourself having to import classes from AWT. To me, It just shows how deep AWT’s roots run.
Swing, the successor to AWT which builds directly onto it, fixing and replacing many of it’s features with better ones or simply adding extra functionality onto existing ones (like tool-tips, borders and icons). The components in Swing are also less resource intensive compare to AWT.
Despite all this though, Swing is quickly becoming a legacy GUI library with it’s use mainly being restricted to old projects which need to be maintained. It would be rare to see a new GUI project nowadays using Swing. The reason for this is the introduction of a newer GUI framework, JavaFX which is meant to replace it.
Swing was a very popular library in it’s prime as it was the best GUI framework (for most) option available. Even now in 2020 it likely still holds a significant portion of the total GUI developers in Java. (mainly in projects that were built using swing in the past). The reason being that it’s hard to make that transition from one framework to the other, especially on a large scale such as a company.
There is an alternative version of Swing called SWT, (Standard Widget Toolkit) created by the IBM group. It was designed for the purpose of creating a more native feel to the GUI and most importantly, creating a GUI framework that runs well (faster) on the Eclipse IDE. Of course, it has it’s own downsides too (when compared to Swing) such as requiring native DLLs across different systems. It’s not really used nowadays, neither is it very recommended.
JavaFX is the latest Flagship of Java/Oracle replacing Swing, promising to be the new standard in creating rich desktop and web applications. Majority of the new Java GUI programs being developed in the last decade have been using JavaFX.
Since it’s one of the newer GUI Libraries introduced in Java, it understandably produces a more modern and rich look to it’s GUI’s than the older Swing and AWT.
One of it’s major selling points is it’s support for Mobile apps. Any JavaFX program you write on desktop/windows will also run on Android and iOS. Another plus point is how JavaFX handles separation between the CSS, FXML and Controller code, making it nice and simple.
If the above reasons weren’t enough to convince you, JavaFX also has a design tool called the “Scene Builder”. It’s basically a drag and drop system where you select components and “drop” them onto the window. Personally I’m not a very big fan of such a thing, (I prefer the traditional way) but I know that alot of people appreciate and use the Scene Builder.
An older library like Swing has the advantage of being older and has had time to fully mature and develop as a GUI framework. However, JavaFX is still receiving updates and improvements so it’s expected that it will catch up soon. In a way it’s actually a good thing that JavaFX is still “evolving” compared to Swing which is no longer being developed.
Learn more about JavaFX through our very own tutorial series!
If you in 2020 (or later) want to learn one of the above Java GUI Frameworks, I highly recommend you go with JavaFX. Swing is still a good GUI framework, but it’s being left behind (due to newer advancements). JavaFX on the other hand likely has a long life span ahead of it before it gets replaced by anything.
Your choice doesn’t have to complete binary either. Due to the way they are built, you can actually use a hybrid of Swing, AWT and JavaFX components in a single GUI. It’s especially useful for people who will be converting a pre-existing Swing or AWT GUI to the newer JavaFX, allowing for a smooth transition.
Hopefully this article was an informative read. There wasn’t much to decide here really (with regards to the best Java GUI Framework) since the choice was fairly one sided, but hopefully you found this little “history lesson” interesting.
This marks the end of the Java GUI Frameworks article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.