user13824394
user13824394

Reputation:

java- Is revalidate() method necessary?

A quick question,

Is it necessary to call revalidate() method each time, you change the location of components?

And what are other instances, when it is necessary to call revalidate() method?

Upvotes: 1

Views: 87

Answers (2)

camickr
camickr

Reputation: 324128

Is it necessary to call revalidate() method each time, you change the location of components?

You should not be setting the location of components. That is the job of the layout manager.

The point of using revalidate() IS to invoke the layout manager so the size/location of the components can be determined based on the rules of the layout manager.

So you invoke revalidate() and typically repaint() AFTER you add or remove components from a visible container.

Upvotes: 1

Roy Yang
Roy Yang

Reputation: 31

Every time you create or modify (location, size or internal content) or remove a component or multiple components, it tells the layout manager the new component list.

Yes, once you change the location, it is necessary to call revalidate().

Upvotes: 2

Related Questions