What is the difference between JPanel and JFrame and relationship to lightweight, heavyweight?
JPanel is container that allows to put several UI components together. JFrame is a window written using Swing.
All Swing components are so-called "lightwight" components because they are written in java. If for example you run Swing application and try to analyze it using UI analyzing tool (e.g. WinSpy in windows) you see only one element: the window (JFrame) itself. All other components are drawn from OS point of view.
Heavyweight API - AWT uses portable elements provided by OS. Since java must be portable among various operating system AWT is very limited. It implements only the minimal subset of screen elements supported by all platforms. However the AWT elements are mapped directly to the appropriate platform elements, so UI discovery tool will see them. These elements are named "heavy weight".
Heavyweight components like "AWT" components must be drawn using native GUI on a specific platform.
Where lightweight components like "Swing" components are drawn by java and don't rely on native GUI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With