What is the difference between AWT & Swing?
Answer Posted / harivardhan.a
Most of the issues related to mixing AWT and Swing
components are related to the mixing of so-called
heavyweight and lightweight components. 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").
(Lightweight component support was introduced in JDK1.1,
and you can read more about it in the
We generally don't recommend mixing Swing and AWT
components because there are significant benefits in
sticking with programs that are written entirely in Swing
(and thus use only lightweight components).
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.
Despite the benefits of using Swing components exclusively,
a developer may sometimes have to mix AWT components and
Swing components in the same program (even when migration
is not to blame). For example, such mixing may be required
when a Swing version of a particular AWT component is not
yet available.
Because there's sometimes no alternative to mixing
heavyweight and lightweight components, we have provided a
few options in Swing to make a certain level of component-
mixing possible. However, as anyone who has tried this
approach knows, there are some practical limitations to
this approach
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.
| Is This Answer Correct ? | 87 Yes | 23 No |
Post New Answer View All Answers
Explain how to render an html page using only swing.
Is there any heavyweight component in swings?
Who created the swing?
What are the components of swing in java?
What is java swing package?
What is swing api?
What is a component in swing?
What is java panel swing?
What is import javax swing jframe?
What is an event in Swing?
Is swing better than awt?
What is swing in java with example?
What are the different types of layout managers used in swing?
What are the advantages of swing?
What is frame in java swing?