Reputation: 20688
Quoting http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html :
As a conveniance
add
and its variants,remove
andsetLayout
have been overridden to forward to the contentPane as necessary. This means you can write:frame.add(child);
And the child will be added to the contentPane.
Quoting from Core Java Volume I - Fundamentals (9th Edition), Chapter 7, Section 7.4.
As of Java SE 5.0, the JFrame.add method has given up trying to reeducate programmers, and simply calls add on the content pane.
Thus, you can simply use the call
frame.add(c);
But when I scroll through the API docs at
http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html, I
can't find any documentation on the add
method in JFrame that
overrides an add
method of a parent class.
In fact, the first occurrence of any add
method I see in this page is
in the 'Methods inherited from class java.awt.Container' section of the
page.
Why is the overridden add
method that JFrame defines is not mentioned
in the API documentation of JFrame?
Upvotes: 1
Views: 371
Reputation: 21995
add
has not been overridden and still is inherited from java.awt.Container
but as you can see below, a call is made to addImpl
which is overridden in JFrame
376 public Component add(Component comp) {
377 addImpl(comp, null, -1);
378 return comp;
379 }
JFrame#addImpl()
Adds the specified child Component. This method is overridden to conditionally forward calls to the contentPane. By default, children are added to the contentPane instead of the frame, refer to RootPaneContainer for details.
Upvotes: 1