Converting Values Between Source and Target Properties (Java Desktop Applications)

See Also

When you bind the values of two properties of two objects, you sometimes need to convert the values between different types.

The beans binding library contains converters for some common conversions. For other conversions, you need to provide a custom converter.

Below is a list of conversions for which you do not need to provide a converter:

To write a custom converter, create a class that extends org.jdesktop.beansbinding.Converter. Your class needs to override the convertForward(S value) and convertReverse(T value) methods. convertForward(S value) converts a value from the source type to the target type. convertReverse(T value) converts a value from the target type to the source type.

To use a custom converter in a binding:

  1. Right-click the converter class in the Projects window and choose Compile File.
  2. Drag the converter from the Projects window to the Design view of your form.

    The converter is added to your form as a bean.

  3. Right-click the target of your binding and choose Bind > TargetProperty.
  4. In the Bind Dialog box, select the Advanced tab.
  5. From the Converter drop-down list, choose the converter you have added to the form.
  6. Click OK.
See Also
Validating Target Value Changes in Bindings
About Beans Binding in Java Desktop Applications
Binding Data to a Swing Component

Legal Notices