1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JGoodies Forms :: Reference :: Cell Constraints</title>
<link rel="stylesheet" type="text/css" href="../style.css" >
<meta name="description" content="The JGoodies Forms helps you layout and implement elegant Panel quickly and consistently.">
<meta name="author" content="Karsten Lentzsch">
<meta name="keywords" content="JGoodies Forms Java Layout Swing UI Design Usability Lentzsch Kiel">
<meta name="robots" content="index, follow">
<meta name="date" content="2003-07-31">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0" bottommargin="0" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td colspan="3" bgcolor="DDDCDC"><a href="../../README.html"><img
src="../images/banner.gif" width="436" height="46" alt=":: JGOODIES :: Forms" border="0"></a></td>
</tr>
<tr>
<td colspan="3" height="1" bgcolor="C9C8C8"></td>
</tr>
<tr>
<td width="160" height="500" valign="top" bgcolor="F4f3f3" class="nav" nowrap="nowrap">
<div style="margin-left: 17px; margin-top: 17px; margin-right: 10px; ; margin-bottom: 17px; line-height: 18px;">
<!-- ************ Anfang der Seitennavigation **************************** -->
<b>General</b>
<br>:: <a class="nav" href="../../README.html">Readme</a>
<br>:: <a class="nav" href="../../RELEASE-NOTES.txt">Release Notes</a>
<br>:: <a class="nav" href="../../LICENSE.txt">License</a>
<br>:: <a class="nav" href="../whitepaper.pdf">Whitepaper</a>
<br>:: <a class="nav" href="../visualbuilders.html">Visual Builders</a>
<br>:: <a class="nav" href="../references.html">References</a>
<br>:: <a class="nav" href="../tips.html">Tips & Tricks</a>
<br>:: <a class="nav" href="http://www.jgoodies.com/freeware/libraries/forms/faq/">FAQ</a>
<p>
<b>Reference</b>
<br>:: <a class="nav" href="alignments.html">Alignments</a>
<br>:: <a class="nav" href="constantsizes.html">Constant Sizes</a>
<br>:: <a class="nav" href="componentsizes.html">Component Sizes</a>
<br>:: <a class="nav" href="boundedsizes.html">Bounded Sizes</a>
<br>:: <a class="nav" href="colsandrows.html">Cols & Rows</a>
<br>:: <a class="nav" href="cells.html"><b>Cell Constraints</b></a>
<br>:: <a class="nav" href="groups.html">Groups</a>
<br>:: <a class="nav" href="variables.html">Layout Variables</a>
<p>
<a class="nav" href="../api/index.html"><b>API Docs</b></a>
<p>
<b>Web Pages</b>
<br>:: <a class="nav" href="http://java.net/projects/forms/">Project Home</a>
<br>:: <a class="nav" href="http://www.jgoodies.com/downloads/libraries/">Download</a>
<br>:: <a class="nav" href="http://www.jgoodies.com/downloads/archive/">Archive</a>
<br>:: <a class="nav" href="http://java.net/projects/forms/lists">Mailing Lists</a>
<br>:: <a class="nav" href="http://java.net/jira/browse/FORMS">Issue Tracker</a>
<!-- *********** Ende der Seitennavigation ******************************* -->
</div>
</td>
<td width="1" bgcolor="E7E5E5"><img src="/images/banner.gif" width="1" height="1" alt=""></td>
<td width="90%" valign="top" >
<div style="margin-left: 20px; margin-top: 17px; margin-bottom: 17px">
<!-- ************ Anfang des Inhalts ***************************************** -->
<table width="530" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<h1>:: Reference :: Cell Constraints ::</h1>
Each component managed by a FormLayout is associated with an instance
of <tt>CellConstraints</tt> that specifies a components
display area and alignment.
The column and row origins are mandatory, but as we will see later, often
a non-visual builder will automatically create the CellConstraints for you.
<p>
By default the column and row span is just 1, and the alignments
are inherited from the related column and row. If possible you should
specify the aligment for the column and row, not for the component;
this way you can reduce the amount of alignment specifications
significantly.
<p>
CellConstraints objects can be constructed in different ways using
a mixture of ints, objects and strings. I recommend to specify
the origin and span using ints and the alignment with strings -
just to increase the code readability.
<h2>Reusing CellConstraints</h2>
You can reuse CellConstraints objects because they are cloned
internally by the FormLayout. Hence you can write a condensed form
<pre>
CellConstraints cc = new CellConstraints();
builder.addLabel("Name", cc.xy(1, 1));
builder.add(nameField, cc.xy(3, 1));
builder.addLabel("Age", cc.xy(1, 3));
builder.add(ageField, cc.xy(3, 3));
</pre>
<h2>Spanning Multiple Columns/Rows</h2>
You can let components span multiple columns or rows,
for example by using the CellConstraints method
<tt>#xywh</tt> where you specify the x and y position
of the leading cell and the width and height of the display area.
<p>
<b>Note:</b> these components do not affect the size of
the spanned columns or rows, nevertheless, they may expand
the whole container. See also the <a href="../faq.html#L.5">FAQ</a>
for details and how to handle this situation.
<h2>Examples</h2>
1) Creation methods intended for use by humans
<pre>
CellConstraints cc = new CellConstraints();
cc.xy(2, 1); // second col, first row
cc.xy(2, 1, "right, bottom"); // aligned to right and bottom
cc.xy(2, 1, "r, b"); // abbreviated alignment
cc.xywh(2, 1, 4, 3); // spans 4 cols, 3 rows
cc.xywh(2, 1, 4, 3, "right, bottom");
cc.xywh(2, 1, 4, 3, "r, b");
</pre>
2) Constructors intended for builders<pre>
new CellConstraints(); // first col, first row
new CellConstraints(2, 1);
new CellConstraints(2, 1, 4, 3);
new CellConstraints(2, 1, CellConstraints.RIGHT,
CellConstraints.BOTTOM);
</pre>
3) Constructors intended for building UIs from XML<pre>
CellConstraints cc = new CellConstraints();
new CellConstraints("2, 1");
new CellConstraints("2, 1, r, b");
new CellConstraints("2, 1, 4, 3");
new CellConstraints("2, 1, 4, 3, r, b");
</pre>
</td>
</tr>
</table>
<!-- ************ Ende des Inhalts ************************************** -->
</div>
</td>
</tr>
<tr>
<td nowrap="nowrap" bgcolor="F4f3f3">
<div style="font-size: 10px; margin-left: 17px; margin-top: 20px; margin-right: 10px; margin-bottom: 4px;">
(c) 2012 JGoodies
</div>
</td>
<td width="1" bgcolor="E7E5E5"></td>
<td> </td>
</tr>
<tr>
<td colspan="2" height="1" bgcolor="E7E5E5"></td>
<td></td>
</tr>
</table>
</body>
</html>
|