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 Container? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why Container?" Watch "Why Container?" New topic

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

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.

SCJP 1.4
I agree. Here's the link:
subject: Why Container?
jQuery in Action, 3rd edition