Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how come swing components are lightweighted !  RSS feed

 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
to all Ranchers , While reading swings i got notice one thing almost all swing components have extended from awt components , while awt components are heavyweight how come swing components( most of them except top level compopnent ) are lightweight , what it is doing while extending that it is becoming lightweight.Can you please explain me this descriptively.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know.

But you know you can sign on as a member of the Sun Java Developers' Network and download a zip file which has the entire coding of the java and javax parts of the standard API and view the code? You might be able to work out something from that.
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Swing components take the look and feel of the OS. Hence they are considered as lightweight. Whereas AWT has a standard look and feel irrespective of the OS on which it is working. Hence it is considered as heavyweight.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's Swing which has a standardised look and feel (well several; there's Metal and there's Motif and I think there is at least one other look and feel).
AWT uses the display capabilities of the underlying OS and therefore looks the same as a Windows, Gnome, OS/X etc look and feel.
Using lots of OS componentry is called "heavyweight."

How it is done, I don't know.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand a bit on what Campbell said, Swing components are considered lightweight because they draw themselves and do not rely on native calls to the OS. AWT (And SWT for that matter) make calls to the OS and say "Hey, I need a button" and the OS throws them back a button. Swing uses the Graphics2D API to draw it's widgets.

Note that not all components in the javax.swing package are lightweight. Namely, top level containers like JFrame are still considered heavyweight components because they extend java.awt.Frame.

This is a good article on why mixing heavy and light weight components are not a good idea and gives a bit more technical information on the differences than I can.
[ August 31, 2006: Message edited by: Gregg Bolinger ]
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

oops, so sorry for that wrong information.
Thanks for correcting me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!