In this article Difference between AWT and Swing we give the information between AWT is a Platform-Dependent and Swing is a Platform-Independent.
Difference between AWT and Swing:
AWT (Abstract Window Toolkit) and Swing are both libraries used to build GUI (Graphical User Interface) in Java, but there are many important differences between them such as follow.
Sr. No. | Points | AWT | Swing |
1 |
Architecture
|
AWT is a Platform-Dependent toolkit, i.e. it depends on the GUI components of the operating system on which the program is running. Components used in AWT are based on the components of the native operating system. | Swing is a Platform-Independent toolkit. All the components of Swing are written entirely in Java and work equally well on any operating system. These are Lightweight components and do not depend on the components of the native operating system. |
2 | Components | AWT components are heavyweight as they use native components of the operating system. For example, the look and feel of buttons, text boxes, etc. depends on the platform on which the program is running. | Swing components are Lightweight and are written entirely in Java, making their look and feel platform independent. Its components are more flexible than AWT. |
3 |
Look and Feel of GUI Components | The look and feel of AWT is platform-dependent, i.e. it varies according to the operating system | Swing has Pluggable Look and Feel, which means you can change the look and feel of the components of a Swing application without changing the code. You can use many looks and feels like Windows, Metal, Nimbus.
|
4 | Component Classes | AWT contains a limited number of GUI components. It has components like Button, Label, TextField, TextArea, Checkbox etc. | Swing contains a lot of advanced components. It includes JButton, JLabel, JTextField, JTextArea, JCheckBox, JRadioButton, JTable, JTree, JComboBox etc. apart from the components of AWT. |
5 | Event Handling | Event handling in AWT is less convenient than Swing. Earlier AWT had the complexity of EventListener, which was later solved in a better way in Swing. | Event handling in Swing is simple and flexible. It has a better event model, which makes event handling easier for programmers. |
6 |
Containers | AWT has containers like Frame, Panel, Window, Dialog. | Swing has advanced containers like JFrame, JPanel, JWindow, JDialog apart from AWT containers which are more flexible and functional. |
7 | Transparency | AWT components do not support transparency. You cannot make the background of these components transparent. | Swing supports transparency. You can make the background of Swing components transparent and customize them. |
8 | Threading Model | The threading model in AWT can be complex and problematic. GUI updates are dependent on the main thread, which makes it slow sometimes. | Swing has an advanced threading model that is handled by the SwingWorker. This ensures that GUI updates happen properly. |
9 | Drawing and Graphics | AWT has limited drawing and graphics support for graphical user interfaces. | Swing has great support for graphics and custom drawing. In Swing you can paint components in a custom way and create advanced 2D graphics.
|
10 | Performance | Since AWT contains heavyweight components, its performance may be slightly slower than Swing. | Swing contains lightweight components, making it lighter and faster than AWT. However, Swing can sometimes be complex due to more components and features. |
Summary:
AWT |
Swing |
Platform-Dependent | Platform-Independent |
Heavyweight components | Lightweight components |
Limited GUI components | Advanced and more GUI components |
Custom GUI components built in Java | Based on native operating system’s GUI |
Limited Look and Feel | Pluggable Look and Feel |
Does not support transparency | Supports transparency |
Some More:
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining