且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-06-01 09:16:19

基本规则是:永远 - 摇摆内部将照顾它。规则的基本例外是在运行时添加/删除组件或者以系统无法知道或由于某种原因不想对其做出反应的方式影响布局的更改。

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.

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

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.