@@ -392,7 +392,8 @@ public Insets insets() {
392392 *
393393 */
394394 public Component add (Component comp ) {
395- return addImpl (comp , null , -1 );
395+ addImpl (comp , null , -1 );
396+ return comp ;
396397 }
397398
398399 /**
@@ -406,7 +407,8 @@ public Component add(Component comp) {
406407 *
407408 */
408409 public Component add (String name , Component comp ) {
409- return addImpl (comp , name , -1 );
410+ addImpl (comp , name , -1 );
411+ return comp ;
410412 }
411413
412414 /**
@@ -435,7 +437,8 @@ public Component add(String name, Component comp) {
435437 *
436438 */
437439 public Component add (Component comp , int index ) {
438- return addImpl (comp , null , index );
440+ addImpl (comp , null , index );
441+ return comp ;
439442 }
440443
441444 /**
@@ -998,7 +1001,8 @@ public void add(Component comp, Object constraints) {
9981001 */
9991002
10001003 public Component add (Component comp , Object constraints , int index ) {
1001- return addImpl (comp , constraints , index );
1004+ addImpl (comp , constraints , index );
1005+ return comp ;
10021006 }
10031007
10041008 /**
@@ -1062,93 +1066,86 @@ public Component add(Component comp, Object constraints, int index) {
10621066 * @see LayoutManager2
10631067 * @since JDK1.1
10641068 */
1065- protected Component addImpl (Component comp , Object constraints , int index ) {
1066- return addImplCont (comp , constraints , index );
1069+ protected void addImpl (Component comp , Object constraints , int index ) {
1070+ addImplCont (comp , constraints , index );
10671071 }
10681072
1069- protected Component addImplCont (Component comp , Object constraints , int index ) {
1070- synchronized (getTreeLock ()) {
1071-
1072- //SwingJS used for all add methods
1073-
1074- /* Check for correct arguments: index in bounds,
1075- * comp cannot be one of this container's parents,
1076- * and comp cannot be a window.
1077- * comp and container must be on the same GraphicsDevice.
1078- * if comp is container, all sub-components must be on
1079- * same GraphicsDevice.
1080- */
1073+ protected void addImplCont (Component comp , Object constraints , int index ) {
1074+ synchronized (getTreeLock ()) {
1075+
1076+ // SwingJS used for all add methods
1077+
1078+ /*
1079+ * Check for correct arguments: index in bounds, comp cannot be one of this
1080+ * container's parents, and comp cannot be a window. comp and container must be
1081+ * on the same GraphicsDevice. if comp is container, all sub-components must be
1082+ * on same GraphicsDevice.
1083+ */
10811084// GraphicsConfiguration thisGC = this.getGraphicsConfiguration();
10821085
1083- if (index > component .size () || (index < 0 && index != -1 )) {
1084- throw new IllegalArgumentException (
1085- "illegal component position" );
1086- }
1087- checkAddToSelf ( comp );
1088- // Here we do not allow JSApplet, but we do allow JInternalFrame, which is a JFrame now
1089- if (comp .isJ2SWindowButNotJInternalFrame ()) {
1090- throw new IllegalArgumentException ("adding a window to a container" );
1091- }
1086+ if (index > component .size () || (index < 0 && index != -1 )) {
1087+ throw new IllegalArgumentException ("illegal component position" );
1088+ }
1089+ checkAddToSelf ( comp );
1090+ // Here we do not allow JSApplet, but we do allow JInternalFrame, which is a
1091+ // JFrame now
1092+ if (comp .isJ2SWindowButNotJInternalFrame ()) {
1093+ throw new IllegalArgumentException ("adding a window to a container" );
1094+ }
10921095
10931096// checkNotAWindow(comp);
10941097// if (thisGC != null) {
10951098// comp.checkGD(thisGC.getDevice().getIDstring());
10961099// }
10971100
1098- /* Reparent the component and tidy up the tree's state. */
1099- if (comp .parent != null ) {
1100- comp .parent .remove (comp );
1101- if (index > component .size ()) {
1102- throw new IllegalArgumentException ("illegal component position" );
1103- }
1104- }
1105-
1106- //index == -1 means add to the end.
1107- if (index == -1 ) {
1108- component .add (comp );
1109- } else {
1110- component .add (index , comp );
1111- }
1112- _childTainted = true ;
1113- comp .parent = this ;
1114-
1115- adjustListeningChildren (AWTEvent .HIERARCHY_EVENT_MASK ,
1116- comp .numListening (AWTEvent .HIERARCHY_EVENT_MASK ));
1117- adjustListeningChildren (AWTEvent .HIERARCHY_BOUNDS_EVENT_MASK ,
1118- comp .numListening (AWTEvent .HIERARCHY_BOUNDS_EVENT_MASK ));
1119- adjustDescendants (comp .countHierarchyMembers ());
1120-
1121- invalidateIfValid ();
1122- if (peer != null ) {
1123- comp .addNotify ();
1124- }
1125-
1126- /* Notify the layout manager of the added component. */
1127- if (layoutMgr != null ) {
1128- if (layoutMgr instanceof LayoutManager2 ) {
1129- ((LayoutManager2 )layoutMgr ).addLayoutComponent (comp , constraints );
1130- } else if (constraints instanceof String ) {
1131- layoutMgr .addLayoutComponent ((String )constraints , comp );
1132- }
1133- }
1134- if (containerListener != null ||
1135- (eventMask & AWTEvent .CONTAINER_EVENT_MASK ) != 0 ||
1136- Toolkit .enabledOnToolkit (AWTEvent .CONTAINER_EVENT_MASK )) {
1137- ContainerEvent e = new ContainerEvent (this ,
1138- ContainerEvent .COMPONENT_ADDED ,
1139- comp );
1140- dispatchEvent (e );
1141- }
1142-
1143- comp .createHierarchyEvents (HierarchyEvent .HIERARCHY_CHANGED , comp ,
1144- this , HierarchyEvent .PARENT_CHANGED ,
1145- Toolkit .enabledOnToolkit (AWTEvent .HIERARCHY_EVENT_MASK ));
1146- if (peer != null && layoutMgr == null && isVisible ()) {
1147- updateCursorImmediately ();
1148- }
1149- }
1150- return comp ;
1101+ /* Reparent the component and tidy up the tree's state. */
1102+ if (comp .parent != null ) {
1103+ comp .parent .remove (comp );
1104+ if (index > component .size ()) {
1105+ throw new IllegalArgumentException ("illegal component position" );
1106+ }
1107+ }
1108+
1109+ // index == -1 means add to the end.
1110+ if (index == -1 ) {
1111+ component .add (comp );
1112+ } else {
1113+ component .add (index , comp );
1114+ }
1115+ _childTainted = true ;
1116+ comp .parent = this ;
1117+
1118+ adjustListeningChildren (AWTEvent .HIERARCHY_EVENT_MASK , comp .numListening (AWTEvent .HIERARCHY_EVENT_MASK ));
1119+ adjustListeningChildren (AWTEvent .HIERARCHY_BOUNDS_EVENT_MASK ,
1120+ comp .numListening (AWTEvent .HIERARCHY_BOUNDS_EVENT_MASK ));
1121+ adjustDescendants (comp .countHierarchyMembers ());
1122+
1123+ invalidateIfValid ();
1124+ if (peer != null ) {
1125+ comp .addNotify ();
1126+ }
1127+
1128+ /* Notify the layout manager of the added component. */
1129+ if (layoutMgr != null ) {
1130+ if (layoutMgr instanceof LayoutManager2 ) {
1131+ ((LayoutManager2 ) layoutMgr ).addLayoutComponent (comp , constraints );
1132+ } else if (constraints instanceof String ) {
1133+ layoutMgr .addLayoutComponent ((String ) constraints , comp );
1134+ }
1135+ }
1136+ if (containerListener != null || (eventMask & AWTEvent .CONTAINER_EVENT_MASK ) != 0
1137+ || Toolkit .enabledOnToolkit (AWTEvent .CONTAINER_EVENT_MASK )) {
1138+ ContainerEvent e = new ContainerEvent (this , ContainerEvent .COMPONENT_ADDED , comp );
1139+ dispatchEvent (e );
1140+ }
1141+
1142+ comp .createHierarchyEvents (HierarchyEvent .HIERARCHY_CHANGED , comp , this , HierarchyEvent .PARENT_CHANGED ,
1143+ Toolkit .enabledOnToolkit (AWTEvent .HIERARCHY_EVENT_MASK ));
1144+ if (peer != null && layoutMgr == null && isVisible ()) {
1145+ updateCursorImmediately ();
1146+ }
11511147 }
1148+ }
11521149
11531150
11541151
@@ -1716,9 +1713,9 @@ protected Dimension preferredSizeContainer() {
17161713 Dimension dim = prefSize ;
17171714 if (dim == null || !(isPreferredSizeSet () || isValid ())) {
17181715 synchronized (getTreeLock ()) {
1719- prefSize = (layoutMgr != null ) ?
1716+ prefSize = (layoutMgr != null ?
17201717 layoutMgr .preferredLayoutSize (this ) :
1721- prefSizeComp ();
1718+ prefSizeComp ()) ;
17221719 dim = prefSize ;
17231720 }
17241721 }
0 commit comments