Solved

Difference between Swing and AWT in java?

Posted on 2004-03-23
9
2,919 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 87
Java DateChooser? 3 29
more than one jdk and one jre 1 30
reverse digits of a number using for loop 5 36
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now