본문 바로가기
IT 실무/JAVA

[AWT&Swing] Repaint, Validate, Invalidate, Revalidate

by 지식id 2012. 12. 4.
반응형

Repaint() 
Repaint() method just repaints the component. It is the method of Component class. Repaint() causes calls paint() method of a Component if it is a lightweight component. It is better to call the repaint method rather than paint method because painting system calls paint at appropriate time which coalesces multiple calls into one call. Another disadvantage of calling paint rather than repaint is it bypasses the double buffering mechanism.


Validate()
Before checking validate first we need to check when we say Component is valid what it means? It means that the Component coordinates has been determined and nothing is changed changing these coordinates. When the Component is created the valid property is false so we can say it as invalid as the coordinates hasn’t been determined. Validate() method validates the component by calling doLayout(). Validation is performed on Container and on its child components recursively which results in all the components to be laid out and validated. Validate() method is necessary when we remove the component and add it again.


Invalidate()
This method makes components invalid , along with all of its ancestor containers up to the
nearest validate root. Validate root can be any container which doesn’t change the size when their child components change size. This method need to call when components needs to have new layout to be done.


Revalidate()
When we call invalidate() it doesn’t automatically calls validate to make Components to be valid again. Revalidates calls invalidate first and then make components valid by calling validate method. Most swing components calls revalidate() method when we change the size of the components and call the repaint method.

[출처] Repaint|작성자 Lifestyle

반응형

댓글