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:

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 Boolean. Default is false. E.g.

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. JFrame.getContentPane() is a example for such a method. The value must be a String and specifies the name of a method that takes no arguments and returns a java.awt.Container. E.g.

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 Class. E.g.

beanDesc.setValue("layoutManager", BorderLayout.class);
persistenceDelegate Specifies an instance of a class, which extends java.beans.PersistenceDelegate, that can be used to persist an instance of the bean. E.g.

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 String.

propDesc.setValue("category", "My Properties");
enumerationValues Specifies a list of valid property values. The value must be a Object[]. For each property value, the Object[] must contain three items:
  • Name: A displayable name for the property value.
  • Value: The actual property value.
  • Java Initialization String: A Java code piece used when generating code.

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 a Object[]. For each class, the Object[] must contain two items:
  • Class: The class for which the persistence delegate should be used.
  • Persistence delegate: Instance of a class, which extends java.beans.PersistenceDelegate, that should be used to persist an instance of the specified class.
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 enumerationValues or PropertyEditor.getJavaInitializationString(). The value must be a String or String[]. E.g.

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 Boolean. Default is false. E.g.

propDesc.setValue("notMultiSelection", Boolean.TRUE);
notNull Specifies that a property can not set to null in the Properties view. If true, the Set Value to null command is disabled. The value must be a Boolean. Default is false. E.g.

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 Boolean. Default is false. E.g.

propDesc.setValue("notRestoreDefault", Boolean.TRUE);
persistenceDelegate Specifies an instance of a class, which extends java.beans.PersistenceDelegate, that can be used to persist an instance of a property value. E.g.

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 highlichted in bold in the Binding dialog. The value must be a Boolean. Default is false. E.g.

propDesc.setValue("preferredBinding", Boolean.TRUE);
readOnly Specifies that a property is read-only in the Properties view. The value must be a Boolean. Default is false. E.g.

propDesc.setValue("readOnly", Boolean.TRUE);
transient Specifies that the property value should not persisted and no code should generated. The value must be a Boolean. Default is false. E.g.

propDesc.setValue("transient", Boolean.TRUE);
variableDefault Specifies whether the default property value depends on other property values. The value must be a Boolean. Default is false. E.g.

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 (Refresh Designer) in the designer tool bar.

Refresh does following:

  1. Create a new class loader for loading JavaBeans, BeanInfos and Icons.
  2. Recreates the form in the active Design view.

Unsupported standard components

  • all AWT components