IntelliJ IDEA
 
Get IntelliJ IDEA
You are viewing the documentation for an earlier version of IntelliJ IDEA.

Generating Accessor Methods for Fields Bound to Data

Last modified: 23 August 2023

If you have fields in the UI class that you want bound to some data in a JavaBean class, IntelliJ IDEA provides a special Data Binding Wizard. This wizard helps generate getData and setData methods for the fields in a UI class that are bound to components in a GUI form. You can create data binding to an existing bean class, or create a new bean class on the fly using the wizard.

For example, suppose you have some JTextField components on a GUI form that are bound to fields in a UI class, and you want the value of their text properties bound to some data in a JavaBean class. Instead of editing the UI class, creating getData and setData methods for the fields, being careful to specify the fully qualified name of the correct bean class and importing the required package, use Data Binding Wizard.

When you finish the wizard, the specified accessor methods are written to the form's class according to the options you specified in the wizard. Import statements are generated in the class as necessary.

Once components have been bound to data, you can invoke Data Binding Wizard again, in which case you are presented with options to either remove the data binding, or bind to a different bean. If you choose the latter option, the wizard enables you to select or create the bean class for the data binding. The source code of the UI class (including imports) is modified according to your choices and specifications.