• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is JFrame added to JFrame heavyweight or lightweight?

 
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
<blockquote>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").
</blockquote>

and further
<blockquote>
all Swing components are lightweight (except for the top-level ones: JWindow, JFrame, JDialog, and JApplet)
</blockquote>

If JFrame instance added to JFrame window, then is it heavyweight or lightweight?

[This message has been edited by G Vanin (edited November 12, 2001).]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi G,
The reason that JFrame, JDialog, JWindow, and JApplet are heavyweight is because the OS draws the outside of them and the OS link must be created and maintained. The components are handled by the OS windowing environment for such things as iconification, maximize, minimize, resize, top/bottom/middle placement, etc.
The OS functionality can not be changed from within Swing for top level components because of the OS link that MUST exist.
Therefore, any time a Swing top-level component is used in a GUI we are using heavy-weight components. The advantage of Swing is that all other Swing components are lightweight and therefore can be customized from within Swing. That is why buttons can look the same no matter what OS is used.
Regards,
Manfred.
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Manfred man,
for clearing me the fact asked.
But logically it was not clear to me.
<blockquote>
the OS link must be created and maintained
</blockquote>
OK, but for a link/reference/pointer, why there is a need for peer (from OS)?
<blockquote>
The OS functionality can not be changed from within Swing for top level components because of the OS link that MUST exist.
</blockquote>
OK for (external) container but why it may not be broken for internals?
In this connection I have a curiosity:

  1. How it is determined inside Swing classes that some may be put directly to desktop while others only to container?


  2. Why it is impossible to get rid of peers, providing just a link, native API interfacing (for iconizing, etc) and drawing directly, i.e. w/o using heavy-weght counter-part peer?

  3. [This message has been edited by G Vanin (edited November 12, 2001).]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't add a JFrame to a JFrame. The reason top-level components are called top-level components is because they are the top-level of the GUI. You can't add a JFrame or any other top-level component inside another container.

-Nate
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nathan,
that was the most difficult part
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manfred Leonhardt:
Hi G,
The reason that JFrame, JDialog, JWindow, and JApplet are heavyweight is because the OS draws the outside of them and the OS link must be created and maintained. The components are handled by the OS windowing environment for such things as iconification, maximize, minimize, resize, top/bottom/middle placement, etc.
Regards,
Manfred.


Hi !
Are you sure JApplet is heavy-weight ?
Hierarchy is Panel-->Applet-->JApplet
so, it shouldn't be ?
Arnaud
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That <blockquote>
all Swing components are lightweight (except for the top-level ones: JWindow, JFrame, JDialog, and JApplet)
</blockquote> was a citation (citations were shifted a little bit to the right in my post) from that cited Sun's link
It is just a first paragraph in section "Heavy vs. light: the differences" inside that link/page
I do not take responsibilities for others, sorry. But I would like to have some more links since I have more questions in this area. For ex.,
  1. in AWT all components are heavy-weight but we can add some (or any? which?) into containers. In Swing top-level is synonym of heavy-weight. Correct? So this logic, that the component may not be added because it is top-level, i.e. heavy-weight, is blurred to me

  2. I also asked somewhere in this forum and did not get to answer:
    what is determining that some component may or may not be shown directly by OS. How to check this in the source?
    what is determining that some component may or may not be added to container?How to check this in the source of that class?

  3. [This message has been edited by G Vanin (edited November 15, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Are you sure JApplet is heavy-weight ?
Hierarchy is Panel-->Applet-->JApplet
so, it shouldn't be ?



Both Panel and Applet are AWT widgets and are heavyweight. JApplet is a special case. Applets were made to be embedded into web-pages, so they need to have a native peer to interact with web browsers ( which are usually written in native code ). Applets are heavy weight, but are not necessarily top-level. They can be thought of as top-level when they are running in a browser, because no Java object contains them... but since they inherit from Panel, they can also be contained within other components.

OK... to clear things up I'll define what I mean by the terms top-level and heavy-weight.

  • Top-Level - Root of the GUI heirarchy, top-level components cannot be contained within other components.
  • Heavy-Weight - Component has a native peer to communicate with the underlying operating system.


  • In AWT, all components were heavy-weight, but only Window, Frame, Dialog, and (sometimes) Applet (and any classes extending these) were top-level. In Swing, JWindow, JFrame, JDialog, and (sometimes) JApplet (and any classes extending them) are heavy-weight, and are also top-level. Applet and JApplet are special cases, as mentioned previously. They are always heavy-weight, but are not always top-level.

    I am not sure how you can check to see if a component is top-level or heavy-weight in the code, other than by looking at what the class extends. Just remember, in AWT all components are heavyweight, and Window, Frame, and Dialog ( and any classes extending them ) are top-level only. In Swing, JWindow, JFrame, JDialog, and JApplet ( and any classes extending them ) are heavy-weight, and JWindow, JFrame, and JDialog( and any classes extending them ) are top-level only.

    -Nate
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathan,
thanks a lot, once more.
I would not have written the following, hadn't I had a great confusion due to difficulties in understanding terminology.
When I see "Top-Level - Root of the GUI heirarchy", I cannot help but having in my head java.lang.Object because, IMHO, by default/omission the hierarchy is always implied with inheritance sense. In other sense the hierarchies are usually qualified.
It is really hard (for me) to shift in my head smth I am accustomed to. You meant "containment hierarchy", right?
It is better if you qualify hierarchies in this forum, please.
Widget is not Java (and I blieve OO) term. I may guess that it is a component. Correct? General or some specification?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic