*
The moose likes Beginning Java and the fly likes what is the meaning of Heavy weighted component and light weighted component. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the meaning of Heavy weighted component and light weighted component." Watch "what is the meaning of Heavy weighted component and light weighted component." New topic
Author

what is the meaning of Heavy weighted component and light weighted component.

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi everybody, I am Chaitanya, while I was going through the differences of awt and swing in java, I came across two terms, heavy weight and light weight component. I read this article in java.sun.com. They quoted a para there.
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").

This is what they quoted. Can anybody tell me what this exactly means.

Thank you all in advance, have a nice day.


There is no rule that we all should know everything. Lets learn few things of everything here.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
just read the rest of the article, it's explained there.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi Michale I read the thing from here. They explained about light weight and heavy wight components clearly. But thing is they said that light weight components borrow screen resource from an ancestor, where as heavy weight component is associated with its own native screen resource.

I did not understand that. Can you please tell me.

I am thinking that Heavy while developing java, the java programmers have written the entire code to draw a window on the screen for the awt package. Where as the swing components give the task to the operating system. Is this correct?

Thank you in advance, have a nice day.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The difference between AWT and Swing components is this: In AWT, each button, textbox, etc. is linked to a corresponding native GUI component from the operating system that the program is running on. In Swing, each textbox, button etc. is not linked to a native GUI component; Swing just draws all those components itself (independent of the underlying operating system).

Because AWT components have to maintain the state of those native GUI components, they are called "heavyweight" - the AWT component has to drag around the native GUI component all the time. Swing components are "lightweight" because they are just Java objects, they don't need to maintain a native GUI component that's linked to it.

(You're asking about the meaning of "heavyweight" and "lightweight" components specifically in the context of AWT and Swing - note that in other contexts, these terms can have different meanings).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi Jesper, thanks for the explanation. But however I did not understand this thing. Can you please tell me once again.
Because AWT components have to maintain the state of those native GUI components, they are called "heavyweight" - the AWT component has to drag around the native GUI component all the time. Swing components are "lightweight" because they are just Java objects, they don't need to maintain a native GUI component that's linked to it.

Thank you in advance.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

What exactly did you not understand? I can tell the same thing to you again, but maybe then you still won't understand...
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
The java AWT components has to drag around the native GUI components. It has to maintain the state of those components. whereas the swing components are just objects.

I did not understand "maintain the state of those objects".
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi all, AWT will maintain the state of the native GUI components, can anybody tell me what is meant by "maintaining the state of the native GUI components".

Thank you all in advance. Have a nice day.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Ok, I'll try to explain it again.

If you create a button in AWT, then in the background, the java.awt.Button object will ask the operating system to create a button (which is some native thing specific to the operating system). The java.awt.Button object will have to keep track of that native button from the operating system. That's a relatively "heavy" operation, compared to just having pure Java objects, as Swing does.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Thank you Jesper.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the meaning of Heavy weighted component and light weighted component.
 
Similar Threads
Swing an AWT
Difference between lightweight and heavyweight objects
lightweight component
Awt VS Swing
swing and Awt