amit
amit

Reputation: 10882

What does Container.validate() method do?

There seems to be many methods in Java awt Container class that are related to validate. Apparently they don't do data validation. Is it useful for a Swing developer in any cases? Some of the methods: validate(), invalidate(), validateTree(), isValid() etc.

Upvotes: 1

Views: 17367

Answers (2)

Adamski
Adamski

Reputation: 54705

Validation in a Swing context concerns requesting a component to lay-out its sub-components after one of these is modified.

For example, suppose you implement a custom JDialog with a button "Show Filters". Upon clicking this button, you might want to add an additional "filter" panel to the south of the JDialog. Upon adding the new sub-panel you would be required to call validate() on the JDialog to cause it to lay-out the new panel correctly.

Upvotes: 3

Michael Borgwardt
Michael Borgwardt

Reputation: 346317

Citing the API doc:

The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.

Upvotes: 8

Related Questions