Swing components are light-weight?
Asked Answered
A

3

5

Whenever I read about Swing they say they are light weight components. So I just googled Swing and found that it means Swing does not depend on native peers. Is that why they are called "light weight"? I mean by light weight I thought maybe the Swing components occupy less memory than the AWT components. Isn't that so?

Alvertaalves answered 6/1, 2009 at 15:23 Comment(0)
T
12

Swing is considered lightweight because it is fully implemented in Java, without calling the native operating system for drawing the graphical user interface components.

On the other hand, AWT (Abstract Window Toolkit) is heavyweight toolkit, as it merely makes calls to the operating system in order to produce its GUI components.

The Evolution of the Swing Paint System section from the Painting in AWT and Swing article explains the difference between lightweight and heavyweight:

When the original AWT API was developed for JDK 1.0, only heavyweight components existed ("heavyweight" means that the component has it's own opaque native window). This allowed the AWT to rely heavily on the paint subsystem in each native platform.

[...]

With the introduction of lightweight components in JDK 1.1 (a "lightweight" component is one that reuses the native window of its closest heavyweight ancestor), the AWT needed to implement the paint processing for lightweight components in the shared Java code.

As Swing is implemented in Java, it does have some performance disadvantage, however, I hear that performance has improved in recent releases of Java.

The advantage of Swing is that it has many more components available such as JTable and JList which are more graphical and extensible than the components provided in AWT, allowing for more graphics-rich applications to be developed.

Trave answered 6/1, 2009 at 15:42 Comment(2)
i agree that there are too many cool things with swing - especially the tooltips and icons .Alvertaalves
In Java 6, the Windows look-and-feel delegates to the OS to draw the lightweight components (see weblogs.java.net/blog/chet/archive/2006/02/these_are_some.html).Grebe
S
8

Lightweight vs heavyweight is a question of how the UI components are implemented. Heavyweight components wrap operating system objects, lightweight components don't. They are implemented strictly in the JDK.

Stardom answered 6/1, 2009 at 15:27 Comment(3)
what can you say about the memory the components occupy pal ? do the swing components occupy less memory ?Alvertaalves
It's hard to say. Lightweight components may occupy more simply because the operating system handles some of the stuff with heavyweight components. Or the overhead of OS objects might be huge. Or simply interfacing those objects might have a huge overhead.Stardom
In addition to this it highly depends on the LAF (Look & Feel) you use. This is one other advantage of Swing: you can change LAF in just a few lines of code.Avionics
P
0

This is simply an addendum that addresses the heavyweight vs. lightweight in another context: programming model.

In this context Swing is definitely heavyweight and complicated. It is not considered suitable for thin client implementation, and given the fact that today there are so many different devices, Swing is, in effect, dead technology, even though Oracle has not retired it...yet (also see JavaFX as an alternative).

Planet answered 18/6, 2016 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.