After knowing what a component is, let us go to the list of containers Java supports. For this, the container hierarchy is separated from the earlier component hierarchy and displayed here.
Infact, the Container is a component as it is a subclass of Component class. It can use all the methods of Component class and an extra added feature is components can be added to this component (container).
- Any class subclass of a Container class is known as a container.
- Only components can be added to container.
- Every container comes with a default layout manager that can be changed explicitly with setLayout() method.
As you can observe from the above hierarchy, Container is the super class of all Java containers.
Following is the class signature
Following are the important methods of the Container class.
- add(): This method is overloaded with which a component can be added to the container.
- invalidate(): Used to invalidate the present set up of components in the container.
- validate(): Used to revalidate the current set up of components after calling invalidate().
The important containers used very often are applets, frames and panels. Rare are dialog boxes. Panels work very differently. Panel behaves both as component and container. As component panel can be added to a container and as container we can add components to panel.
No comments:
Post a Comment