Solved

Difference between Swing and AWT in java?

Posted on 2004-03-23
9
2,940 Views
Last Modified: 2013-11-23
What is difference between Swing and AWT in java and what do u mean by Heavyweight and lightweight component?
0
Comment
Question by:skirfan
  • 4
  • 3
9 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 25 total points
ID: 10657247
AWT generally use platform specific components, so look&feel is platform dependent.
Swing is a standard set of components whose look&feel is standard and can be changed (metal, windows, mac).

Heavyweight : native component
lightweight : component you create by subclassing the Component (or JComponent) class.
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 25 total points
ID: 10657253
Difference between Swing in Java? Let's say Swing has advanced features for everything that AWT has. Most of the things would have a 'J' prefixed. Like Frame will become JFrame, Dialog will become JDialog. But well, Swing gives you a lot more.... like the javax.swing.text package, the JEditorPane where you can display HTML/ plain-text (make a browser using that), JTree (if you wanna make Yahoo messenger ;-) ), JFileChooser, JOptionPane for customized dialog-boxes, JColorChooser, displaying images inside labels (JLabels), buttons (JButtons), etc
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10657262
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.

The differences boil down to the following:

- A lightweight component can have transparent pixels; a heavyweight is always opaque.
- A lightweight component can appear to be non-rectangular because of  its ability to set transparent areas; a heavyweight can only be rectangular.
- Mouse events on a lightweight component fall through to its parent;  mouse events on a heavyweight component do not fall through to its parent.
- When a lightweight component overlaps a heavyweight component, the  heavyweight component is always on top, regardless of the relative z-order of the two components.

Courtesy: http://java.sun.com

http://java.sun.com/products/jfc/tsc/articles/mixing/
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 13

Expert Comment

by:Webstorm
ID: 10686362
Other important difference between lightweight and heavyweight components i tested (application & applet) :
    heavyweight component are still visibles when they are in an invisible lightweight container.

0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10686372
And may be another one :
    Using a ScrollPane, the following AWT subtree:
          ScrollPane
          +---  lightweight component
    become when scrollpane is made visible:
          ScrollPane
          +---  Panel
                 +---  lightweight component

0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10686407
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10859152
Please proceed with that recommendation.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 21
HSSFWorkbook cannot be resolved error 10 71
stackato and cloud 4 86
web application structure 18 77
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question