Swing vs AWT. Basically AWT came first and is a set of heavyweight UI components (meaning they are wrappers for operating system objects) whereas Swing built on top of AWT with a richer set of lightweight components.
Any serious Java UI work is done in Swing not AWT, which was primarily used for applets.
As far as when AWT may be more useful than Swing -
The base difference that which already everyone mentioned is that one is heavy weight and other is light weight. Let me explain, basically what the term heavy weight means is that when you're using the awt components the native code used for getting the view component is generated by the Operating System, thats why it the look and feel changes from OS to OS. Where as in swing components its the responsibility of JVM to generate the view for the components. Another statement which i saw is that swing is MVC based and awt is not.
Swing vs AWT. Basically AWT came first and is a set of heavyweight UI components (meaning they are wrappers for operating system objects) whereas Swing built on top of AWT with a richer set of lightweight components.
Any serious Java UI work is done in Swing not AWT, which was primarily used for applets.
Several consequences result from this difference between AWT and Swing.
AWT is a thin layer of code on top of the OS, whereas Swing is much larger. Swing also has very much richer functionality. Using AWT, you have to implement a lot of things yourself, while Swing has them built in. For GUI-intensive work, AWT feels very primitive to work with compared to Swing. Because Swing implements GUI functionality itself rather than relying on the host OS, it can offer a richer environment on all platforms Java runs on. AWT is more limited in supplying the same functionality on all platforms because not all platforms implement the same-looking controls in the same ways.
Swing components are called "lightweight" because they do not require a
native OS object to implement their functionality. JDialog
and JFrame
are
heavyweight, because they do have a peer. So components like JButton
,
JTextArea
, etc., are lightweight because they do not have an OS peer.
A peer is a widget provided by the operating system, such as a button object or an entry field object.
Swing:
AWT:
Several consequences result from this difference between AWT and Swing.
AWT is a thin layer of code on top of the OS, whereas Swing is much larger. Swing also has very much richer functionality. Using AWT, you have to implement a lot of things yourself, while Swing has them built in. For GUI-intensive work, AWT feels very primitive to work with compared to Swing. Because Swing implements GUI functionality itself rather than relying on the host OS, it can offer a richer environment on all platforms Java runs on. AWT is more limited in supplying the same functionality on all platforms because not all platforms implement the same-looking controls in the same ways.
Swing components are called "lightweight" because they do not require a
native OS object to implement their functionality. JDialog
and JFrame
are
heavyweight, because they do have a peer. So components like JButton
,
JTextArea
, etc., are lightweight because they do not have an OS peer.
A peer is a widget provided by the operating system, such as a button object or an entry field object.
As far as when AWT may be more useful than Swing -
The base difference that which already everyone mentioned is that one is heavy weight and other is light weight. Let me explain, basically what the term heavy weight means is that when you're using the awt components the native code used for getting the view component is generated by the Operating System, thats why it the look and feel changes from OS to OS. Where as in swing components its the responsibility of JVM to generate the view for the components. Another statement which i saw is that swing is MVC based and awt is not.
Java 8
The base difference that which already everyone mentioned is that one is heavy weight and other is light weight. Let me explain, basically what the term heavy weight means is that when you're using the awt components the native code used for getting the view component is generated by the Operating System, thats why it the look and feel changes from OS to OS. Where as in swing components its the responsibility of JVM to generate the view for the components. Another statement which i saw is that swing is MVC based and awt is not.
AWT 1 . AWT occupies more memory space 2 . AWT is platform dependent 3 . AWT require javax.awt package
swings 1 . Swing occupies less memory space 2 . Swing component is platform independent 3 . Swing requires javax.swing package
Swing vs AWT. Basically AWT came first and is a set of heavyweight UI components (meaning they are wrappers for operating system objects) whereas Swing built on top of AWT with a richer set of lightweight components.
Any serious Java UI work is done in Swing not AWT, which was primarily used for applets.
The base difference that which already everyone mentioned is that one is heavy weight and other is light weight. Let me explain, basically what the term heavy weight means is that when you're using the awt components the native code used for getting the view component is generated by the Operating System, thats why it the look and feel changes from OS to OS. Where as in swing components its the responsibility of JVM to generate the view for the components. Another statement which i saw is that swing is MVC based and awt is not.
AWT 1 . AWT occupies more memory space 2 . AWT is platform dependent 3 . AWT require javax.awt package
swings 1 . Swing occupies less memory space 2 . Swing component is platform independent 3 . Swing requires javax.swing package
Swing:
AWT:
Java 8
Source: Stackoverflow.com