Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between components and lightweight/heavyweight

Tags:

java

swing

awt

What is the difference between JPanel and JFrame and relationship to lightweight, heavyweight?

like image 793
Bulent Avatar asked Dec 07 '12 18:12

Bulent


2 Answers

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".

like image 97
AlexR Avatar answered Sep 22 '22 10:09

AlexR


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.

like image 37
Ahmed Mostafa Avatar answered Sep 23 '22 10:09

Ahmed Mostafa