File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Why Container? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why Container?" Watch "Why Container?" New topic
Author

Why Container?

Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
As in AWT ,when we extends Frame,we can directly
add components e.g Panel on Frame like add(p1).
but why when we use Swing and Extends Jframe we cannot directly add component to Jframe,first we have to create Container c = getContentPane()
and then add panel to it?
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
The Swing containers are a little more complex. There's a single child of a JFrame called a JRootPane. This pane contains the content pane, the menu bar (if there is one), and a layered pane and glass pane.
You add your user-components to the content pane. The other panes are used for different things. For example, drawing into the glass pane will draw your component on top of everything else.
There's a good swing tutorial on using JRootPane. You should look up the API docs for JRootPane and read up on it.


Rob
SCJP 1.4
 
 
subject: Why Container?