Creating properties
To create a property in a class source:
- Find the class in the Explorer, expand its node, and right-click on
Bean Patterns
.![]()
- In the contextual menu, choose New | Property. The New Property Pattern dialog box will appear, which will enable you to customize the code to be generated for the property.
- Type in a name for the property. (The name must be a valid Java identifier.)
- In the Type combo box, choose the type of property from the list, or type in a class identifier.
- In the Mode combo box, choose whether to have the getter method (
READ ONLY
), setter method (WRITE ONLY
), or both methods (READ/WRITE
) generated.- Check the Bound (meaning that property change events must be fired when the property changes) and/or Constrained (meaning that the property change can be vetoed) options, if applicable to the property. The usefulness of checking these options is enhanced if you also check the Generate Property Change Support option - see below.
![]()
If you click OK after these steps, the definitions of the methods will be generated. However, you can also check all or any combination of the following options:
- If you check the Generate field option, a private field is generated. This field will have the same name and type as the property.
- If you check the Generate return statement, a statement that returns the field (for example,
return myProperty;
) is inserted in the body of the getter method.- If you check the Generate set statement option, a statement setting the value of the property field to the value of the setter parameter will be inserted into the body of the setter method.
- If you check Generate property change support, all of the code needed for firing
PropertyChangeEvents
(for bound properties) andVetoableChangeEvents
(for constrained properties) will be generated in the bodies of the setter methods. In addition, code to declare and initialize the property change support object is generated.
Contents | Prev | Next | Index |