Message-ID: <908007798.789296.1386572220363.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_789295_1896463396.1386572220362" ------=_Part_789295_1896463396.1386572220362 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
While SwingBuilder comes with almost all of the standard Swing w= idgets, sometimes you need to add custom or extended components. There are = several ways to accomplish this.=20
SwingBuilder has two 'magic' elements that pass through the value argume=
nt or the named attribute to the parent container. The
element has been in Groovy since 1.0. New in Groovy 1.1Beta2 is the
ontainer element. Currently they are identical in behavior and shoul=
d be used mostly to increases code readability: elements that can contain c=
hildren should use
s should contain no children. (in a future build this restriction may be en=
forced at the builder level).
To use the widget or container elements you pass in the desired custom w=
idget or custom container object as the value argument or the
container: attributes respectively.
Most widgets accept a widget of the appropriate type in the value argume= nt of the swing builder element. If your extended component extends a commo= n swing widget type you can supply an instance of that component in the val= ue argument.=20 =20
If your custom component follows the JavaBeans specification, specifical=
ly having a no-argument public constructor, then you can register your comp=
onent directly with the SwingBuilder and use it as a first class element. T=
o do this call the
registerBeanFactory(String, Class) method w=
ith the desired element name and Bean class.
Sometimes you will need greater interaction with the supplied values in =
the SwingBuilder, or you want to accomplish richer things with the supplied=
arguments. In this case you can register a custom factory. Custom factorie=
groovy.swing.factory.Factory and are registered vi=
registerFactory(String, Factory) method.
All of the elements that do interesting things with their argument value=
s and that need to access different constructors or lack no-argument constr=
uctors utilize this interface. Tricks such as accessing the Action construc=
tors in the button type widgets, using the
tory methods are two such real world examples.