Forums Register Login

JFrame.getContentPane()

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
i think they are same, JFrame method add(component) will inside call getContentPane().add(component) finally. Not 100% sure.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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().
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4616 times.
Similar Threads
Is JFrame added to JFrame heavyweight or lightweight?
Getting All The componts in a JFrame
Applet refuses to repaint
What's difference between JPanel and JComponent?
can i add a container to another container
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:20:22.