Creating and Exposing a Property

Defining a control property is similar to adding a property to any Java class. In addition, however, you add members to the ClassInfo class to make your property visible in the Properties window.

In this topic you can find information about the following:

Adding a Property Definition

A property is stored in a private member variable of your control. You then provide a public get<property> method to expose the property value. If you intend to make the property read-write, you also provide a public set<property> method that takes a parameter containing the new property value.

Note   The WFC Component Builder will create property skeletons for you.

A simple integer property called myProp in the MyControl control might be implemented as in the following example:

public class MyControl extends Control{
   private int myProp = 0; // 0 is the default value
   public getMyProp(){
      return myProp;
   }
   public setMyProp( int newValue ){
      myProp = newValue;
   }
}

Note   The name used in the property definition should start with a lowercase letter, unless the first two letters are uppercase. The function names should have a capital letter immediately following the get or set. For example; text would have getText and setText, while MDIChild would have getMDIChild and setMDIChild.

Exposing a Property at Design Time

To make your property visible in the Properties window, you do the following:

The following example shows the ClassInfo class for the myProp property:

public static class ClassInfo extends Control.ClassInfo {
   public static final PropertyInfo myProp = 
         new PropertyInfo(MyControl.class, "myProp", int.class);
   public void getProperties(IProperties props){
      // Add existing properties from parent class
      super.getProperties(props);
      props.add(myProp);      // adds custom property
   }
}

For more information about the use of the PropertyInfo class, see Specifying Custom Property Attributes.