From JavaDoc:
public void validate()Validates this container and all of its subcomponents. Validating a container means laying out its subcomponents.
That is what I want to do. With an as lightweight component as possible. But when I do this whith a JComponent a call to validate() doesn’t 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 a JComponent valid?
In the docs for
isValid()it says:This is the case until you reach a Top-Level Container (
JFrame,JInternalFrameorJApplet). In the example you have in your question, yourJComponentdoesn’t have a parent so it can never be valid.