Documentation

Code Templates

When generating new Java files or classes, JFormDesigner uses the templates specified in the Preferences dialog.

Template name Description
File header Used when creating new Java files. Contains a header comment and a package statement.
Class Used when generating a new (nested) class. Contains a class declaration, a constructor, a component initialization method and variable declarations.
Empty Class Used when generating a new empty class. This can happen, if all form components are contained in nested classes.
Event Handler Body Used for event handler method bodies.
Component Initialization Replaces the variable ${component_initialization} used in other templates. Contains a method named initComponents. Invoke this method from your code to instantiate the components of your form. Feel free to change the method name if you don't like it.
Component I18n Initialization Used for code that initializes localized component properties if option "Generate initComponentsI18n() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties.
Component Binding Initialization Used for code that initializes bindings if option "Generate initComponentBindings() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties.
Variables Declaration Replaces the variable ${variables_declaration} used in other templates.
java.awt.Dialog Used for classes derived from java.awt.Dialog. Compared to the "Class" template, this has special constructors, which are necessary for java.awt.Dialog derived classes.
java.awt.Frame Used for classes derived from java.awt.Frame. Equal to the "Class" template, but necessary because java.awt.Frame extends java.awt.Window, which has its own template and a constructor that is not compatible with java.awt.Frame.
java.awt.Window Used for classes derived from java.awt.Window. Compared to the "Class" template, this has a special constructor, which are necessary for java.awt.Window derived classes.
javax.swing.AbstractAction Used for nested action classes.

You can change the existing templates or create additional templates in the Preferences dialog. It is possible to define your own templates for specific superclasses.

Following variables can be used in the templates:

Variable name Description Context
${date} Current date. global
${user} User name. global
${package_declaration} package statement. If the form is not saved under one of the source folders specified in the Project dialog, the variable is empty (no package statement will be generated). file header
${class_name} Name of the (nested) class. class
${component_initialization} See template "Component initialization". class
${constructor_modifiers} Modifiers of the constructor. Based on the class modifiers. class
${extends_declaration} The extends declaration of the class; empty if the class has no superclass. class
${modifiers} Modifiers of the (nested) class. You can specify the default modifiers in the Preferences dialog. class
${variables_declaration} See template "Variables declaration". class