aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JFrame.getContentPane() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame.getContentPane()" Watch "JFrame.getContentPane()" New topic
Author

JFrame.getContentPane()

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi all,
I want to add a component into top-level container.
In here, I use JFrame as top-level container.
My understanding is there are 2 ways to do that..
1. I use JFrame method getContentPane().add(component);
2. Because of JFrame is subclass of java.awt.Containter, I can use JFrame method add(component) directly.

Is it true?
Are there performance effect between both?

thanks
daniel
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
i think they are same, JFrame method add(component) will inside call getContentPane().add(component) finally. Not 100% sure.


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
Calling add() on the frame directly will give a runtime error:

java.lang.Error: Do not use add() use getContentPane().add() instead
[ November 15, 2004: Message edited by: Sebastiaan Kortleven ]
Ted Reynolds
Greenhorn

Joined: Mar 16, 2004
Posts: 20
I thought that in 1.5 they changed it so that the two methods work the same. But of course if you are working with anything from 1.2 to 1.4 you need to use the getContentPane().add().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame.getContentPane()
 
Similar Threads
can i add a container to another container
Applet refuses to repaint
Getting All The componts in a JFrame
Is JFrame added to JFrame heavyweight or lightweight?
What's difference between JPanel and JComponent?