4753342: The top-level swing component should redirect add / remove methods in ContentPane
Description:
Unlike AWT programming, JFrame / JDialg / JWindow / JApplet / JInternalFrame do not allow you to add Component , instead you should learn about JRootPane and add Component children to it. This adds unnecessary confusion to new developers.
Prior to 5.0, attempting to add or remove Component from one of this upper level Component will throw an exception. In 5.0, an exception will not be thrown; instead, Component will be added or removed from the content area. This has led to several revisions to javadoc JFrame , JDialog , JWindow , JApplet and JInternalFrame . This has been summarized in the RootPaneContainer's Javadoc:
* For conveniance * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>, * <code>JApplet</code> and <code>JInternalFrame</code>, by default, * forward all calls to <code>add</code> and its variants, * <code>remove</code> and <code>setLayout</code> to the * <code>contentPane</code>. This means rather than writing: * <pre> * rootPaneContainer.getContentPane().add(component); * </pre> * you can do: * <pre> * rootPaneContainer.add(component); * </pre> * <p> * The behavior of <code>add</code> and its variants and * <code>setLayout</code> for * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>, * <code>JApplet</code> and <code>JInternalFrame</code> is controlled by * the <code>rootPaneCheckingEnabled</code> property. If this property is * true, the default, then <code>add</code> and its variants and * <code>setLayout</code> are * forwarded to the <code>contentPane</code>, if it is false, then these * methods operate directly on the <code>RootPaneContainer</code>. This * property is only intended for subclasses, and is therefor protected.