[java] Why is Swing called "lightweight"?

Started by
18 comments, last by tebriel 19 years ago
Shouldn't it be called heavyweight, rather than AWT, meaning it's less efficient and bogs down the system more than AWT does? Why the heck did they choose to use that terminology??
Advertisement
Cause when you put it on a secure digital card, the source to it isn't that heavy.. Especially when compared to the weight of awt on a set of floppy disks..
Not sure about this, but I believe AWT uses windows/controls/components/... from the underlying OS for each of its controls (which are called heavyweight components), while Swing only uses one such "OS-bound container component", and all other components are handled (the clicking and painting etc) by Swing itself. AWT just uses the OS GUI, while Swing implements it all itself.

Quote:Original post by SamLowry
AWT just uses the OS GUI, while Swing implements it all itself.
Which would make Swing heavyweight, and AWT lightweight.
In an OS like Windows, a window is a quite heavy resource to use. The system has to keep track of all the windows, and make sure that every process on the system will have up to date information and access to it.

Window-less controls, such as those implemented by the IE and Office team are much friendlier and actually required since they would otherwise deplete the system's GUI resources.

The down side to window-less controls is that they require more manual handling and support in the application. That is solved in Java by letting swing implement the hard parts of it.

For more information about windowed vs. windowless controls on Windows, read these entries at The Old New Thing.
Windows are not cheap objects
Windowless controls are not magic

To make it is hell. To fail is divine.

Zao: Those two articles were interesting.... thanks!
BRING BACK THE BLACK (or at least something darker)
http://www.javalobby.org/eps/swt_intro/?source=archives

Go and listen to slide 4. and 5.
Quote:
Shouldn't it be called heavyweight, rather than AWT, meaning it's less efficient and bogs down the system more than AWT does? Why the heck did they choose to use that terminology??

I don't know where you got this, it's the opposite.

Here is an interesting article:
http://java.sun.com/products/jfc/tsc/articles/mixing/index.html

and here some parts of it:
Quote:
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").
...
Some of the benefits of using Swing components are:
-More efficient use of resources: Lightweight components are really "lighter" than heavyweight components.
-More consistency across platforms because Swing is written entirely in Java.
-Cleaner look-and-feel integration: You can give a set of components a matching look-and-feel by implementing them using Swing.

...

There are some significant differences between lightweight and heavyweight components. And, since all AWT components are heavyweight and all Swing components are lightweight (except for the top-level ones: JWindow, JFrame, JDialog, and JApplet), these differences become painfully apparent when you start mixing Swing components with AWT components.

...

The differences boil down to the following:
-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.
In other words, Java butchered the common meanings of heavyweight/lightweight.
Quote:Original post by nuvem
In other words, Java butchered the common meanings of heavyweight/lightweight.


It depends on what your 'common' definitions of heavyweight and lightweight are !
if you mean 'heavy in terms of system resources and window handles' then they got it dead right. On the other hand you mean 'heavy in terms of the (infitesimally small) time it takes to draw a Swing widget then you are right. I'd tend to come down in the former camp myself :-)

D.

This topic is closed to new replies.

Advertisement