This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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?
Similar Threads
badly stuck with GUI problem
extends Frame help
Getting Swing to Work
Adding a window to a container
badlt stuck with GUI problem