CookFormLayout Tutorial: PanelBuilder



Support This Project


stats counter


Logo Logo IntelliJ IDEA

Tutorial Example

tutorial_panelbuilder.xml in the CookFormLayout Java Web Start demo.


<panelbuilder> is provided mainly for the completeness sake. Developers really should just use <formbuilder> instead.

PanelBuilder mainly offers two benefits over the basic FormLayout. One is the ability to add a separator component, another is the linking a JLabel component with another Swing component. However, since I have provided <form-separator> for <formlayout>, all there left is the simple linking and adding a text label with a Swing component.

1. Specify PanelBuilder

To use the PanelBuilder, first place <panelbuilder> inside a <panel> tag, and then place a <formlayout> tag inside the <panelbuilder>.

			columnspec="pref, 4dlu, 50dlu, 4dlu, min"
			rowspec="pref, 2dlu, pref, 2dlu, pref, 2dlu, pref"
			<form-rowgroup rows="3, 5, 7"/>

It is very important to have the <formlayout specified or errors would occur.

2. Add a Separator

With <panelbuilder>, it is not necessary to specify the cellconstraints attribute if the separator is the first row component. <form-label> is specifically for this purpose.

		<form-separator text="<panelbuilder> Tutorial"/>

3. Add and Link a Label with a Swing Component

The main attraction of using a Builder is to link a text label with a Swing component. <panelbuilder> can do it quite easily.

		<form-label text="Label &amp;1"
			labelconstraints="1, 3" componentconstraints="3, 3, 3, 1"

By comparison, adding/linking components without using <form-label is significantly more complicated.

		<cellconstraints xy="1, 7">
			<label text="Label 3" displayedmnemonic="VK_3" labelfor="id:field3"/>
		<cellconstraints xy="3, 7">
			<textfield id="field3"/>

(c) Copyright 2004-2007 Heng Yuan. All rights reserved.

Valid XHTML 1.0! Valid CSS!