CookFormLayout Tutorial: Templates


 

 

Support This Project

 

stats counter

 

Logo SourceForge.net Logo IntelliJ IDEA

Tutorial Example

tutorial_templates.xml in the CookFormLayout Java Web Start demo.

Introduction

JGoodies Forms offers ButtonBarFactory which produces some predefined layouts for buttons. Well, one can do similar things with XML using the <include of CookXml. This tutorial is not really CookFormLayout specific since one could do a much wider range of things with <include.

1. Write a Template Layout

Say one has a template layout for Add and Remove buttons. We can define them in template_addremove_left.xml

<panel>
	<buttonbarbuilder>
		<form-add gridded="true" related="true">
			<button id="addButton" text="Add" mnemonic="VK_A"/>
			<button id="removeButton" text="Remove" mnemonic="VK_R"/>
		</form-add>
		<form-glue/>
	</buttonbarbuilder>
</panel>

Note that I assign an id for each button. The purpose is to be able to refer to these buttons later on.

2. Include the Template

We can then include this template inside the XML file where we need the panel.

		<include ctor="examples/cookformlayout/xml/template_addremove_left.xml"/>

3. Hook Listeners

Since we have assigned buttons with certain ids, we can refer them after we include the template panel. Then we can hook up listeners like what we do normally in CookSwing.

		<noadd>
			<button idref="addButton" actionlistener="addAction"/>
		</noadd>

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

Valid XHTML 1.0! Valid CSS!