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

查看:446
本文介绍了什么时候需要在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()吗?对于其他一些属性,swing是否会自动调用?

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?

推荐答案

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

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.

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

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