Difference between AWT vs Swing
AWT or Abstract Window Toolkit is nothing but an application software used for creating and developing system or web applications. On the other hand, Swing is a Java based application that is built on the AWT as its platform. When comparing Swing with AWT, Swing incorporates all the specifications of AWT along with other plus points, such as more user friendly user interfaces, independently operable from other fellow components, provides a variety of operations and built-in components, platform independent as it is based on Java, etc.
Overview of AWT: AWT is used for supporting user interface in Java Application. It provides the high-level abstraction for Java program since it hides underlying GUI details. Since AWT is an api build on Operating system to provide a graphical user interface for Java. Its component has a dependency on underlying counterpart (like look and feel of that OS) to handle their functionality. Thus, these components are often called “heavyweight” components.
AWT Features Includes:
- A rich set of user interface components.
- The robust event handling model
- Layout Manager for different window layout
- Data transfer classes support cut-paste through the native platform.
Overview of Swing: Swing is built on AWT, it is part of Java Foundation Classes. Swing is based on Java completely that’s why its platform is independent. It is used to create more effective GUI than AWT.
Features of Swing:
- All features of AWT
- Provides a rich set of higher-level components like a tree, tabbed panes, list boxes, etc.
- Pluggable look and feel.
- No dependency on peer components.
Head to Head Comparison Between AWT and Swing (Infographics)
Below is the top 11 comparison between AWT vs Swing:
Key Differences of AWT and Swing
As AWT is a bridge between the application and underlying native interface, implementing it on a new operating system can include a lot of work. Because it requires a native peer to be developed again. The use of native peer limits the functionality of AWT. AWT has two levels of APIs –
- One provides a basic general interface between the application and the native OS.
- Second GUI widget that provides code-behind objects driven on AWT canvas.
Use of native components makes AWT fast. Hence improves its performance. Also, most web browser supports AWT, there is no need of Java plugin for AWT Applets. But AWT has a smaller set of components, thus users have to write custom code to get their own AWT based components. AWT components do not support features like title bar and menu bars.
Swing is the extension of AWT. It is not the exact replacement of AWT. Hence it has AWT features with the extensibility of JAVA. So, all the components that are present in AWT are also present in Swing. But Swing doesn’t require peer programming hence making it platform independent and lightweight. Also, Swing allows for a greater range of components.
Swing is a modular based architecture. It supports plugging for custom implementation. User can create their own implementation to override the default Java-based implementation. Swing also provides support for runtime mechanism. Indirect composition method allows the swing to respond to runtime changes according to the application environment. Swing supports features like icons and tool-tips. Sun is actively involved in the development of Swing hence every now and then swing gets new features and gets better than earlier.
Most of the web browser does not support swing. Thus, one needs to have Java plugin for swing. Swing is slower as compared to AWT. Since Swing components handle their own painting (rather than using native API’s like DirectX on Windows) this may run into graphical glitches.
AWT and Swing Comparison Table
Below is the comparison table between AWT and Swing.
|AWT stands for Abstract Window Toolkit.||Swing is part of Java Foundation Classes (JFC).|
|AWT is platform dependent. Its code resides in OS of the system hence makes it impossible for platform independence.||Swing components are made in JAVA. Thus, making it platform independent.|
|AWT components are heavyweight.||Swing components are lightweight.|
|AWT does not follow MVC (Model View Controller).||Swing is based on MVC.|
|AWT components requires java.awt.package||Swing components require javax.swing.package.|
|AWT does not have Jtable and Jtabbed pane.||Swing has Jtable and Jtabbed pane.|
|AWT is platform-dependent hence not very different look and feel is supported.||Swing can have different look and feel.|
|AWT occupies more memory space.||Swing occupies less memory space.|
|AWT is less powerful than Swing.||Swing is the extension of AWT thus many drawbacks are removed.|
|Look and Feel of AWT is dependent on the platform.||Look and feel of Swing is independent of the underlying platform and operating system.|
|AWT components depend on native code (peers) to function properly. That’s why these components are “Heavy Weight Components”.||Swing has no such dependency. Hence these components are “Light Weight Components”.|
Both are used for creating a graphical user interface in Java. They both are robust and have their own pros and cons. AWT component is appropriate for simple app development that is mostly designed to run on a single OS. Whereas swing is the latest interface which is completely build on Java. Swing gives the user freedom to code once and runs anywhere. It also provides a wider range of components than AWT. It totally depends on user requirements. Although AWT is old development which is still happening in AWT and it is getting better. If the requirement is to have a look and feel more like the underlying operating system, then AWT would be a better option. If you want a more flexible GUI then swing is good to go with.
This has been a guide to the top difference between AWT vs Swing. Here we have discussed AWT vs Swing head to head comparison, key difference along with infographics and comparison table. You may also have a look at the following articles to learn more –
- Java vs Ruby – Which One Is Better?
- Python vs Scala – Top Differences
- Difference between HTML5 vs Flash
- WordPress vs Drupal
- JavaFX Label
- JavaFX Layouts
- Types and How to Create JavaFX Charts?
- JavaFX Slider
- How to Input Text in JavaFX TextField?
- Constructors and Methods of JavaFx Button
- Top 15 Methods of HBox in JavaFX