简体   繁体   English

Container.validate()方法有什么作用?

[英]What does Container.validate() method do?

There seems to be many methods in Java awt Container class that are related to validate . Java awt Container类中似乎有许多与validate有关的方法。 Apparently they don't do data validation. 显然,他们不进行数据验证。 Is it useful for a Swing developer in any cases? 在任何情况下对Swing开发人员有用吗? Some of the methods: validate(), invalidate(), validateTree(), isValid() etc. 一些方法:validate(),invalidate(),validateTree(),isValid()等。

Citing the API doc : 引用API文档

The validate method is used to cause a container to lay out its subcomponents again. validate方法用于使容器再次布置其子组件。 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. 在Swing上下文中进行的验证涉及在修改其中一个子组件后请求组件对其子组件进行布局。

For example, suppose you implement a custom JDialog with a button "Show Filters". 例如,假设您使用“显示过滤器”按钮实现了自定义JDialog。 Upon clicking this button, you might want to add an additional "filter" panel to the south of the JDialog. 单击此按钮后,您可能想要在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. 添加新的子面板后,您将需要在JDialog上调用validate()以使其正确布局新面板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM