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 are swing components?
What are the components of java swing?
Is java swing deprecated?
What are the swing components in java?
What are the different components that are used to show a container?
Which window contains the swing controls?
What is java swing application?
What are the advantages of swing?
What are the features of swing in java?
What is difference between awt and swing?
What is the difference between applications and applets?
What is the process of setting the layout manager?
What is swing components in java?
What is the difference between invokeAndWait() and invokeLater()?
How to link two forms in java swing?