File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes why JFrame is heavy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why JFrame is heavy?" Watch "why JFrame is heavy?" New topic

why JFrame is heavy?

Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Could anyone tell me what could be the reason behind the universal Java truth that JFrame is not extended from JComponent ?

- Vinod<br />-------<br />SCJP2
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Top level components (like Frame, JFrame, Window, JWindow, Dialog, JDialog, even JApplet) are a special case... they have to have a native peer (i.e. Each JFrame has a reference to a Windows (or Motif, or Mac, etc.) frame that it is drawn onto.), and they cannot be drawn inside other components (i.e. You can't put a JFrame inside another JFrame... JApplet's the special case of special cases here, because it can.) I would assume that Sun did this because they already had the code in place for a Frame, Applet, Window or Dialog to get a reference to a native peer and didn't want to have to duplicate that for JFrame, JApplet, JWindow, and JDialog.

However, to get around the problem of top level components not being JComponents, all the new Swing top level components have a root pane that does extend JComponent... which is the reason that you can't add JComponents directly to the JFrame, etc. and have to add it to the content pane (which is inside the layered pane, which is inside the root pane).


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: why JFrame is heavy?
It's not a secret anymore!