Documentation
JavaBeans
What is a Java Bean?
A Java Bean is a reusable software component that can be manipulated visually in a builder tool.
JavaBean (components) are self-contained, reusable software units that can be visually composed into composite components and applications. A bean is a Java class that:
- is public and not abstract
- has a public "null" constructor (without parameters)
- has properties defined by public getter and setter methods.
JFormDesigner supports:
- Visual beans (must inherit from
java.awt.Component
). - Non-visual beans.
BeanInfo¶
JFormDesigner supports/uses following classes/interfaces specified in the java.beans package:
- BeanInfo
- BeanDescriptor
- EventSetDescriptor
- PropertyDescriptor
- PropertyEditor (incl. support for custom and paintable editors)
- Customizer
If you are writing BeanInfo classes for your custom components, you can specify additional information needed by JFormDesigner using the java.beans.FeatureDescriptor extension mechanism.
You can also use BeanInfo Annotations to specify these attributes without the pain of implementing BeanInfo classes.
For examples using BeanInfo Annotations, example implementations of BeanInfo classes and PropertyEditors, take a look at the examples.
BeanDescriptor Attributes¶
Following attributes are supported in BeanDescriptor:
Attribute Name | Description |
---|---|
isContainer | Specifies whether a component is a container or not. A container can
have child components. The value must be a beanDesc.setValue("isContainer", Boolean.TRUE); |
containerDelegate | If components should be added to a descendant of a container, then it is
possible to specify a method that returns the container for the
children. beanDesc.setValue("containerDelegate", "getContentPane"); |
layoutManager | Allows the specification of a layout manager, which is used when adding
the component to a form. If specified, then JFormDesigner does not allow
the selection of a layout manager. The value must be a beanDesc.setValue("layoutManager", BorderLayout.class); |
persistenceDelegate | Specifies an instance of a class, which extends
beanDesc.setValue("persistenceDelegate", new MyBeanPersistenceDelegate()); |
PropertyDescriptor Attributes¶
Following attributes are supported in PropertyDescriptor:
Attribute Name | Description |
---|---|
category | Specifies the property category to which the property belongs.
JFormDesigner adds the specified category to the
Properties view. The value must be a propDesc.setValue("category", "My Properties"); |
enumerationValues | Specifies a list of valid property values. The value must be an
propDesc.setValue("enumerationValues", new Object[] { "horizontal", JSlider.HORIZONTAL, "JSlider.HORIZONTAL", "vertical", JSlider.VERTICAL, "JSlider.VERTICAL", }); |
extraPersistenceDelegates | Specifies a list of persistence delegates for classes. The value must be
an
Use the attribute "persistenceDelegate" (see below) to specify a persistence delegate for the property value. Use this attribute to specify persistence delegates for classes that are referenced by the property value. E.g. if a property value references classes MyClass1 and MyClass2: propDesc.setValue("extraPersistenceDelegates", new Object[] { MyClass1.class, new MyClass1PersistenceDelegate(), MyClass2.class, new MyClass2PersistenceDelegate(), }); |
imports | Specifies one or more class names for which import statements should be
generated by the Java code generator. This is useful if you don't use
full qualified class names in propDesc.setValue("imports", "com.mycompany.MyConstants"); propDesc.setValue("imports", new String[] { "com.mycompany.MyConstants", "com.mycompany.MyExtendedConstants", }); |
notMultiSelection | Specifies whether the property is not shown in the
Properties view when multiple components are
selected. The value must be a propDesc.setValue("notMultiSelection", Boolean.TRUE); |
notNull | Specifies that a property can not set to propDesc.setValue("notNull", Boolean.TRUE); |
notRestoreDefault | Specifies that a property value can not restored to the default in the
Properties view. If true, the Restore
Default Value command is disabled. The value must be a propDesc.setValue("notRestoreDefault", Boolean.TRUE); |
persistenceDelegate | Specifies an instance of a class, which extends
propDesc.setValue("persistenceDelegate", new MyPropPersistenceDelegate()); |
preferredBinding | Specifies that a property is a preferred binding property. If true, the
property is added to the Bind
submenu (right-click on component) and highlighted in bold in the
Binding dialog. The value must be
a propDesc.setValue("preferredBinding", Boolean.TRUE); |
readOnly | Specifies that a property is read-only in the
Properties view. The value must be a
propDesc.setValue("readOnly", Boolean.TRUE); |
transient | Specifies that the property value should not persisted and no code
should generated. The value must be a propDesc.setValue("transient", Boolean.TRUE); |
variableDefault | Specifies whether the default property value depends on other property
values. The value must be a propDesc.setValue("variableDefault", Boolean.TRUE); |
Design time¶
JavaBeans support the concept of "design"-mode, when JavaBeans are used in a GUI design tool, and "run"-mode, when JavaBeans are used in an application.
You can use the method java.beans.Beans.isDesignTime()
in your JavaBean to
determine whether it is running in JFormDesigner or in your application.
Reload beans¶
JFormDesigner automatically reloads classes of custom JavaBeans when changed. So you can change the source code of used custom JavaBeans, compile them in your IDE and use them in JFormDesigner immediately without restarting.
You can also manually reload classes:
- Stand-alone: Select View > Refresh Designer from the menu or press F5.
- IDE plug-ins: Click the Refresh Designer button
(
) in the designer tool bar.
Refresh does following:
- Create a new class loader for loading JavaBeans, BeanInfos and Icons.
- Recreates the form in the active Design view.
Unsupported standard components
- all AWT components