aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why a window can not add to a container? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why a window can not add to a container?" Watch "why a window can not add to a container?" New topic
Author

why a window can not add to a container?

laura_zpf
Ranch Hand

Joined: Sep 14, 2000
Posts: 30
The Container methods add(Component comp) and add(String name, Component comp) will throw an IllegalArgumentException if "comp" is a:
a) button
b) list
c) window
d) textarea
e) container that contains this container
The answer is c),e).
why the window can not add to the container? and by the way, the container aslo can not add to the container?
Ramesh Donnipadu
Ranch Hand

Joined: Sep 16, 2000
Posts: 100
A window is a top level class and cannot be incorporated into other components. So you cannot add window to a container.
You can add one container to other in general. However the question is adding a container to a container which has the former container. Getting confused?
Suppose you have container A which has several buttons, textfields, labels etc. You can add other containers (say B, C etc.) to A. Suppose A itself is added to another container Z. Then you cannot add Z to A.
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
That�s an interesting question!
I remember reading Tony Alicea explanation where he said that although add method, defined in Container class has signature add(Component comp), attempt to add a window will cause IllegalArgumentException.
I looked at add() method code. All overloaded versions of it merely call addImpl method, whose comments said:

/* Check for correct arguments: index in bounds,
* comp cannot be one of this container's parents,
* and comp cannot be a window.
*/

here is part of addImpl code:

Interesting, that java API� description for add methods never mentioned that Window cannot be added to a container.
I believe that you can add Panel or Applet to a container.

[This message has been edited by Mapraputa Is (edited September 20, 2000).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why a window can not add to a container?