开发者

When does one need to call revalidate() on a swing component to make it refresh, and when not?

When dealing with swing components, and when changing开发者_JS百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜