什么时候需要在 Swing 组件上调用 revalidate() 以使其刷新,什么时候不需要? [英] When does one need to call revalidate() on a swing component to make it refresh, and when not?

查看:42
本文介绍了什么时候需要在 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.

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

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?

推荐答案

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

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.

虽然异常不是很明确,但它在正常"应用程序开发中的频率很低:如果需要经常"调用它,代码很可能有问题,f.i.自定义模型实现不通知其侦听器.

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.

这篇关于什么时候需要在 Swing 组件上调用 revalidate() 以使其刷新,什么时候不需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆