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 jpanel swing?
How to move from one page to another in java swing?
What is an event in Swing?
What is swing control in java?
What is difference between jframe and swing?
Is swing still used?
What is difference between applet and swing?
What is the process of setting the layout manager?
What are differences between swing and awt?
What is java swing used for?
When we should go for codebase in applet?
What are the two key features of swing?
Which method is used for setting security in applets?
What is swing delegation event model in java?
What is the difference between invokeAndWait() and invokeLater()?