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 getContentPane() 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 "getContentPane()" Watch "getContentPane()" New topic


selvas kumars
Ranch Hand

Joined: Jan 06, 2001
Posts: 115
what is the use of getContentPane() in swings??What difference it makes?
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
In short, the getContentPane() allows you to get a hand on the JPanel instance contained in a JFrame. It is handy when you want to add components, because you can not add components directy to a JFrame instance.
Anyway if you try to do it, you won't get any compilation error or warning (If anybody can tell me why, I would be pleased) but a runtime error:
java.lang.Error: Do not use Toto.add() use Toto.getContentPane().add() instead
if Toto is an instance of JFrame.
I agree. Here's the link:
subject: getContentPane()
Similar Threads
getContentPane() in JFrame
When does a peer get set?
Layout Manager Question(s)
Converting an Application into JApplet