Why can't I check JComponent?

From JavaDoc :

public void validate()

Checks this container and all its subcomponents. Checking a container means highlighting its subcomponents.

Here is what I want to do. With the lightest component possible. But when I do this with JComponent, the call validate()does not make the component "valid".

    JComponent c = new JComponent() {};
    System.out.println(c.isValid()); // false
    c.validate();
    System.out.println(c.isValid()); // false

Why can't I make it JComponentvalid?

+2
source share
3 answers

The docs for isValid()say:

A component is valid if it is correctly installed and placed in its parent container, and all its children are also valid.

, (JFrame, JInternalFrame JApplet). , , JComponent , .

+4

Javadoc java.awt.Component.isValid() :

, , .

, , .

0

To add answers to the above, do not forget to override the method getPreferedSize()to return the size of your component. Otherwise, the layout manager will not position yours JComponent, therefore, it will not be displayed.

0
source

Source: https://habr.com/ru/post/1746983/


All Articles