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
What is swing container?
What is the purpose of action interface in swing?
Hello Everyone.. I m trying to develop a java swing application where i can display a doc file Jeditorpane or Jtextpane.
Explain the difference between jfc & wfc.
Why would you use swingutilities.invokeandwait or swingutilities.invokelater?
What is the function of lightweight components used in swing?
Why are swings considered lightweight?
Why swings are called lightweight components?
What is the function of abstractaction class?
What is swing gui?
What are swing controls?
Is swing better than awt?
Which layout does swing use by default?
What is the mean of swing?
What are heavy weight components ?