Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just read the rest of the article, it's explained there.
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15274
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15274
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15274
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic