Modifying GUI Source Code
See Also
The IDE automatically generates blue guarded blocks of code as you create
your GUI form in the GUI Builder. However, you can modify the way initialization
code is generated
and even write custom code to be placed
within the initialization code.
Modifying Code Generation for Form Components
You can modify the way initialization code is generated for a component,
form, or component property by editing its Code properties in the Properties
window. In addition, you can write custom code and specify where it should be
placed within the initialization code.
To modify a form component's guarded block:
- In the Inspector window, select the component whose initialization code
you want to edit.
- Click the Code button at the top of the Properties window to view the Code
properties.
- Select
the property you wish to edit and enter the desired value.
The IDE updates
the selected component's guarded code block with the new value.
Modifying Code Generation for a Property
The IDE enables form component properties to be initialized in more ways
than simply setting static values.
The IDE enables you to initialize property values from:
- A static value you define
- A component written to the JavaBeans architecture
- A property of another component on the form
- A call to a method of the form or one of its components. You can choose
from a list of methods that return the appropriate data type.
- Code you define, which will be included in the generated code
To modify the initialization code generated for a component's property:
- Select the component in the Inspector window.
- Click the Properties button at the top of the Properties window.
- Select the property for which you would like to modify the initialization
code.
- Click the ellipsis (...) button to bring up the Property Editor dialog
box.
- Select Form Connection from the Select Mode combo box.
- In the Property Editor, select the type of initialization code you would
like to add (Value, Bean, Property, Method Call, or User Code).
- If you select Value or User Code, you must add a static value or your
custom initialization code in the field provided.
- If you select Bean, Property, or Method Call, you can select from
a list of valid options.
The IDE adds the new code to the selected component's guarded block.
- You can also place custom code before or after
a property's initializer. To do this, follow steps 1 through 4 above, and then
click the Advanced button to bring up the Advanced Initialization Code
dialog box. Type your custom pre-initialization code, post-initialization
code, or both in the fields provided.
Modifying GUI Form Code Outside of the IDE
In the IDE each form is comprised of two files:
- A .java file, which contains the form's Java source code.
-
A .form file, which stores the information that is used to generate the
.java file when you make changes to the form in the GUI Builder.
This file does not need to be distributed with your application. If you delete
this file, you can no longer use the GUI Builder to change the form.
You can edit the .java files using external editors (not
while the form is being edited in the IDE), with the following exceptions:
- Do not modify the content of the initComponents() method. The body of
this method is always regenerated when the form is opened in the IDE.
-
Do not remove or modify any of the special comments placed in the source by the IDE's
GUI Builder (// GEN-...). They are required for the form to open
correctly. These comments are not visible inside the IDE's Source Editor.
- Do not modify the headers or footers of event handlers.
- See Also
- Editing Component Properties
- Configuring the GUI Builder
- About Java GUIs
Legal Notices