blob: a634d3d10b1fecf62eeef1208f07e76cad89baf4 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
<TITLE>Custom Layouts</TITLE>
<link rel="stylesheet" type="text/css" HREF="../book.css">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H3>Custom layouts</H3>
<P>Occasionally you may need to write your own custom
<a href="../reference/api/org/eclipse/swt/widgets/Layout.html"><strong>Layout</strong></a>
class. This is most appropriate when you have a complex layout that is used
in many different places in your application. Note that unless you are
writing a very generic layout that will be used by several
<strong><a href="../reference/api/org/eclipse/swt/widgets/Composite.html">Composite</a></strong>
widgets, it is sometimes simpler and easier to calculate sizes and position
children in a resize listener.</P>
<P>Layouts are responsible for implementing two methods:</P>
<ul>
<li><strong>computeSize(...)</strong> calculates the width and height of a
rectangle that encloses all of the composite's children once they have
been sized and placed according to the layout algorithm. The hint
parameters allow the width and/or height to be constrained. For example,
a layout may choose to grow in one dimension if constrained in another.</li>
<li><strong>layout(...)</strong> positions and sizes the composite's children.
A layout can choose to cache layout-related information, such as the
preferred extent of each of the children. The <strong>flushCache</strong>
parameter tells the <a href="../reference/api/org/eclipse/swt/widgets/Layout.html"><strong>Layout</strong></a>
to flush cached data, which is necessary when other factors besides the
size of the composite have changed, such as the creation or removal of
children, or a change in the widget's font.</li>
</ul>
<p>A third method, <strong>flushCache(...)</strong>, can be optionally
implemented to clear any cached data associated with a specific control.
Often, the computeSize() method of a widget can be expensive, and so layouts
can cache results to improve performance.</p>
<p>Further discussion of custom layouts can be found in
<a href="http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm">Understanding
layouts in SWT</a>.</p>
</BODY>
</HTML>