Monday, October 17, 2011

Swing is a light weight component, and awt is a heavy weight component, why?

A heavyweight component is one that is associated with its own  native screen resource (commonly known as a peer). A lightweight component is one that "borrows" the screen resource of an ancestor  (which means it has no native resource of its own -- so it's "lighter").
  • A lightweight component can have transparent pixels; a heavyweight  is always opaque.
  • A lightweight component can appear to be non-rectangular because of  its ability to set transparent areas; a heavyweight can only be rectangular.
  • Mouse events on a lightweight component fall through to its parent;  mouse events on a heavyweight component do not fall through to its parent.
  • When a lightweight component overlaps a heavyweight component, the  heavyweight component is always on top, regardless of the relative z-order  of the two components. 
-----------
 Light weight Component takes the components from the jvm, means it does not request the operating System for getting the components. Swings are light weight components. thats why swing look and feel is different and same on every operating System. Where as, heavy weight components are depending on the O.S. if we request a button component, then JVM ask the button to the os and then it give to the JVM. it is very time consuming process. So awt look and feel is depending on the os. It changes from one os to another os.

No comments: