Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why JFrame is heavy?

 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone tell me what could be the reason behind the universal Java truth that JFrame is not extended from JComponent ?
Vinod
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic