开发者

What does Container.validate() method do?

开发者 https://www.devze.com 2022-12-09 08:20 出处:网络
There se开发者_如何转开发ems 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? So

There se开发者_如何转开发ems 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消