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


Please Help Members By Posting Answers For Below Questions

What is jpanel swing?

554


How to move from one page to another in java swing?

608


What is an event in Swing?

597


What is swing control in java?

539


What is difference between jframe and swing?

505






Is swing still used?

492


What is difference between applet and swing?

531


What is the process of setting the layout manager?

582


What are differences between swing and awt?

520


What is java swing used for?

528


When we should go for codebase in applet?

611


What are the two key features of swing?

523


Which method is used for setting security in applets?

587


What is swing delegation event model in java?

547


What is the difference between invokeAndWait() and invokeLater()?

588