(Difference between revisions)
Line 1: Line 1:
===Can I create forms by extending other forms?===
===Can I create forms by extending other forms?===

Revision as of 16:52, 6 November 2009

Can I create forms by extending other forms?

Let's suppose you want to create one form to be a base (superclass) for other forms (extending the base one). You can create the base form as usual, but it should match the requirements described in Creating a custom container bean :

  • it must be a bean (with public constructor without parameters),
  • it must be compiled at the time when used (i.e. when editing the extending forms),
  • it must be either empty (no components) or have an empty container delegate defined.

To create a form that extends the base form, use the Bean Form template and set its superclass to the base form class.

If you are surprised by seeing an empty form in the GUI builder while the base form had some subcomponents, it can be caused by one of these two reasons:

  1. There is no empty container delegate defined, so the GUI builder clears the original container. See the Creating a custom container bean entry how to specify the container delegate.
  2. Or you see the container delegate itself. If the form is of Window type then the GUI builder can't display it directly in the design area, it only displays the container delegate.


  • If the base form class is a JFrame, make sure its defaultCloseOperation property is set to DO_NOTHING (if set to EXIT, the class could not be instantiated for the extending form).
  • You can add new components to the extending form and change the properties exposed by the base form class.
  • It is not possible to change the subcomponents and the layout of the base form from the extending form.
  • When designing the extending form, you'll see the name of the base form class in the Inspector tree (it shows the class that is being extended).
  • Any changes made in the extending form won't affect the base form class.
  • Changes made in the base form will affect all forms extending it.

Tip for iterative development:

If you change something in the base form, don't forget to compile it. If there are some extending forms opened at the same time, they won't be updated automatically, you must reopen them manually to load the new base class (to do it quickly, invoke 'Reload Form' action on the root form node in Inspector).

  Applies to: All NetBeans versions
  Platforms: All
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo