?
Solved

Difference between Swing and AWT in java?

Posted on 2004-03-23
9
Medium Priority
?
3,032 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 100 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

765 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