Java Glossary : validate

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : V words : validate.

validate
check that a container is valid and if not, calls layout or validateTree to calculate the exact positions and sizes of all the contained components. validate effectively redoes the layout if necessary deciding on new sizes and locations of all the components in the container.

In contrast pack does a validate after computing the size for a frame or window based on the preferred sizes of all the contained components. So pack tends to shrink the layout where validate leaves it the same size but rearranges the contents.

Most often you call validate or pack after a frame or other container been composed, just before the Frame.setVisible(true). validate is also called as the second step in processing a COMPONENT_RESIZED event. Invoking invalidate by itself will not schedule a validate. Invoking validate by itself will not schedule a repaint. repaint does not automatically schedule a validate before the paint. If your recent layout changes (e.g. button adding/removing) are not showing up, make sure you do a validate prior to any repaint.

Note that you can validate an invisible container, and it will leave room for all the components inside it. However, if one of the components inside it, itself, is currently invisible, then the layout manager will typically not leave room for it.

Even though validate does nothing if the layout is already valid, don't call validate unnecessarily. Wait until just before the setVisible or repaint to avoid the overhead of calculating the entire layout just to deal with some tiny change.

While you are composing a Frame you usually would temporarily setVisible( false ), waiting until all the components are added, before allowing any validate/ repaints to be triggered, then validate() then setVisible( true ) when you were ready for your masterwork to be revealed. Traditionally you do the setVisible( false ) in the constructor and the validate() and setVisible( true ) in the code that calls the constructor.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 1620.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/validate.html J:\mindprod\jgloss\validate.html