tags:

views:

1524

answers:

3

Whenever I remove and add swing components from say JPanel, shall I perform call on validate or revalidate?

+2  A: 

I would think revalidate() is what you want. The validate() method will be automatically called for you after a call to revalidate(). See the Java API for JComponent.revalidate().

Nicholas Smith
+4  A: 

revalidate() would be better. revalidate() marks all the container upto the top level as not proper or not valid. Then it calls validate() on the top level. The validate() method of the parent checks if at least one of its immediate children is signaled invalid or improper. it calls validate of the parent. so calling revalidate() automatically means calling validate().

sazamsk
+1  A: 

revalidate() is basically a invalidate() followed by a validate().

Look at Sun's Java source code.

You want to call revalidate().

Avrom