# How does widget revalidation work?

**URL:** <https://forum.microej.com/t/how-does-widget-revalidation-work/650>\
**Category:** Guides\
**Tags:** ui\
**Created:** [January 27, 2020, 12:48pm UTC](https://forum.microej.com/t/how-does-widget-revalidation-work/650 "2020-01-27T12:48:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![microej\_official](https://forum.microej.com/user_avatar/forum.microej.com/microej_official/32/45_2.png) [@microej\_official](https://forum.microej.com/u/microej_official)\
**Post date:** [January 27, 2020, 12:48pm UTC](https://forum.microej.com/t/how-does-widget-revalidation-work/650/1 "2020-01-27T12:48:24Z")

</div>

The validation lays out the widgets in a hierarchy. It follows these steps:

1. Starting from the panel, each container (Panel, Composite) calls the `validate(int, int)` method of its children. This method goes recursively in the hierarchy. The arguments of this method are the area (width, height) available for this renderable.
2. When the `validate(int, int)` method of a renderable returns, its preferred size is set.
3. After this, starting from the panel, each container calls the `setBounds(int, int, int, int)` method of its children to actually lay out the renderable.

[StyleRenderable](http://developer.microej.com/javadoc/microej_5.x/addons/ej/widget/StyledRenderable.html) adds a notion of content, where dimensions are handled without the border, margin and padding (boxing) specified in the style.

[StyledWidget](http://developer.microej.com/javadoc/microej_5.x/addons/ej/widget/StyledWidget.html) and [StyledComposite](http://developer.microej.com/javadoc/microej_5.x/addons/ej/widget/StyledComposite.html) contains an implementation of `validate()` and `setBounds()` that uses `validateContent()` and `setBoundsContent()`.

## Typical flow

 ![image](https://forum.microej.com/uploads/default/original/1X/021715bd1d747ffb1b40089421fcbfb21c0e9f5a.png)

## revalidate() vs revalidateSubtree()

[revalidate()](http://developer.microej.com/javadoc/microej_5.x/addons/ej/mwt/Widget.html#revalidate--) is a method that triggers a new asynchronous validation of the full panel (it requires the panel to be [invalidated](http://developer.microej.com/javadoc/microej_5.x/addons/ej/mwt/Widget.html#invalidate--)).

[revalidateSubtree()](http://developer.microej.com/javadoc/microej_5.x/addons/ej/mwt/Widget.html#revalidateSubTree--) is a method that triggers a new asynchronous validation of the widget and its children.

If only the widget or its children have changed, it is preferable to use revalidateSubtree to avoid useless computation.

## revalidate() vs repaint()

[repaint()](http://developer.microej.com/javadoc/microej_5.x/addons/ej/mwt/Renderable.html#repaint--) will trigger an asynchronous render. Whereas, revalidate will trigger the validation phase before doing a render.

Revalidate should only be used when the layout has changed.

---

<div class="post-metadata">

**Author:** ![microej\_official](https://forum.microej.com/user_avatar/forum.microej.com/microej_official/32/45_2.png) [@microej\_official](https://forum.microej.com/u/microej_official)\
**Post date:** [January 28, 2020, 2:52pm UTC](https://forum.microej.com/t/how-does-widget-revalidation-work/650/2 "2020-01-28T14:52:05Z")

</div>

Listed on January 28, 2020, 2:52pm UTC



---

<div class="post-metadata">

**Author:** ![gaetan.harel](https://forum.microej.com/user_avatar/forum.microej.com/gaetan.harel/32/44_2.png) [@gaetan.harel](https://forum.microej.com/u/gaetan.harel)\
**Post date:** [February 3, 2020, 9:01am UTC](https://forum.microej.com/t/how-does-widget-revalidation-work/650/3 "2020-02-03T09:01:14Z")

</div>

Closed on February 3, 2020, 9:01am UTC


