Component class - Methods - AWT and Swing

Q.  Where are the following four methods commonly used?

1) public void add(Component c)
2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
4) public void setVisible(boolean)

- Published on 19 Oct 15

a. Graphics class
b. Component class
c. Both A & B
d. None of the above

ANSWER: Component class
 

    Discussion

  • Nirja Shah   -Posted on 15 Dec 15
    - A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user.

    - Examples of components are the buttons, checkboxes, and scrollbars of a typical graphical user interface.

    - The Component class is the abstract superclass of the nonmenu-related Abstract Window Toolkit components.

    - Class Component can also be extended directly to create a lightweight component.

    - A lightweight component is a component that is not associated with a native window.

    - On the contrary, a heavyweight component is associated with a native window.

    - The isLightWeight() method may be used to distinguish between the two kinds of the components.

    - Lightweight and heavyweight components may be mixed in a single component hierarchy.

    - However, for correct operating of such a mixed hierarchy of components, the whole hierarchy must be valid.

    - When the hierarchy gets invalidated, like after changing the bounds of components, or adding/removing components to/from containers, the whole hierarchy must be validated afterwards by means of the Container.validate() method invoked on the top-most invalid container of the hierarchy.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)