AWT vs. Swing....why use Swing?
awt, java, swing
Solution
"how can it be lightweight if it uses AWT and inherits the AWT container?"
Lightweight means that the Swing component does not have native peer of it's own, it shares a (common) native peer. This native peer comes from the AWT container it is added to (this is typically the window) and is shared amongst all the Swing components within that container hierarchy...
AWT provides the "heavy" lifting, connecting to the native OS and providing the core channel through which Swing components get rendered. It also provides much of the native integration, such as the `SystemTray`, `Desktop` and per pixel translucency APIs which can be used by Swing
Why use Swing over AWT then....why not just use AWT?
This is matter of opinion, but generally, AWT was replaced by Swing and provides a much more flexible graphical API from which to develop. Because it doesn't rely on the platforms native components, it means you are free to develop components that you need and can be made to run across multiple platforms.
Swing also borrows much of the AWT API, including the Event Queue
`JTree` and `JTable` would be my first argument for using Swing over AWT ;)
Would AWT slow the Swing components down?
Not really. AWT has been using DirectX and OpenGL pipelines for some time now and because it's a translation layer between the native API's and the Java API's, it's generally pretty good at what it does. Besides, without AWT, you don't have Swing...
Problem
I have been doing some reading on AWT vs Swing, but I am not really clear on how Swing works. I have read that Swing sits on top of AWT and that it is lightweight (as opposed to AWT). My question is "how can it be lightweight if it uses AWT and inherits the AWT container?" I am confused. Why use Swing over AWT then....why not just use AWT? Would AWT slow the Swing components down?