Difference between AWT vs Swing
Java is a platform-independent application development software. It provides a set of software that can be used to develop applications. One such software is AWT (Abstract Window Toolkit). It is a set of program interface that is used to create a Graphical user interface (GUI) components and other services required for GUI in Java. It is part of Java Foundation Classes. It makes the development of GUI easier. AWT includes a set of windowing, graphics and user interface widgets. It also has a robust event- handling, imaging tools, a layout manager for flexible window layouts. In this topic, we are going to learn about AWT vs Swing and their differences
Swing is the most recent toolkit based on AWT. Swing gives programmer flexibility of platform independence. Unlike AWT programmer can create more generalized GUI objects using Swing.
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 vs Swing (Infographics)
Below is the top 11 comparison between AWT vs Swing:
Key Differences of AWT vs 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.
4.6 (3,144 ratings)
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.
Comparison table between AWT vs 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 AWT vs Swing 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 also discuss the AWT vs Swing key differences 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