什么时候需要对 swing 组件调用 revalidate() 以使其刷新,什么时候不需要?

发布于 2024-11-03 05:54:06 字数 149 浏览 4 评论 0原文

在处理 swing 组件以及在运行时更改组件时,(通常)需要调用组件上的 revalidate() 方法才能刷新它们。

确定是否需要重新验证组件的规则是什么?当组件上的某些属性发生变化时,swing 是否会自动调用 revalidate(),而对于其他某些属性则不会?

When dealing with swing components, and when changing the components during runtime, one (often) needs to call the revalidate() method on the components in order for them to refresh.

What are the rules that determine whether or not one needs to revalidate a component? Does swing automatically call revalidate() when some certain properties on a component changes, and for some other properties not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2024-11-10 05:54:06

基本规则是:永远不会——摆动内部会处理它。该规则的基本例外是在运行时添加/删除组件或更改以系统无法知道或出于某种原因不想做出反应的方式影响布局。

虽然例外情况不是很明确,但在“正常”应用程序开发中很少见:如果需要“经常”调用它,则代码很可能出现问题,因为自定义模型实现没有通知其侦听器。

The basic rule is: never - swing internals will take care of it. The basic exception to the rule is adding/removing components at runtime or changes which effect layout in ways the system can't know or for some reason doesn't want to react to.

While the exception is not very clearcut, it's infrequency in "normal" application development is: if there's a need to "often" call it there's a high probability something wrong with the code, f.i. a custom model implementation not notifying its listeners.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文