Designing Java GUIs with the GUI Builder
See Also
The IDE's GUI Builder enables you to design GUI's (graphical user
interfaces) visually. As you create and modify your GUI, the IDE automatically
generates the Java code to implement the interface. GUI forms are indicated
by form nodes (
)
in the Projects, Files, and Favorites windows.
Using the GUI Builder
Whenever you open a GUI form, the IDE displays it in a Editor tab with
toggle buttons enabling you to switch between Source and Design views. The
Design view enables you to work with GUI forms visually while the Source view
permits editing of the form's source code directly. Each time you select a form's Design
toggle button, the Palette, Inspector, and Properties windows appear automatically.
Typically, components are added to a form using the Palette window and arranged
in the GUI Builder workspace. As you work, the GUI Builder automatically displays
guidelines suggesting preferred alignment and anchoring for the components you add.
Using the Inspector window in conjunction
with the Properties window, you can then examine and adjust properties of a
form's components and layout managers, manage component event handlers, and
define how code is generated.
- By default, the GUI Builder uses the GroupLayout layout manager for
all new forms you create. If you want to use another layout manager, you can do so by
right-clicking the container, choosing Set Layout, and then choosing
the desired layout manager.
- In order for interfaces that you create with the GroupLayout layout
manager to run
outside of the IDE, they must have the Swing Layout Extensions
library available. The Swing Layout Extension Library is included in
version 6 of the Java Platform, so no additional steps are needed if
you develop the application with JDK 6 and deploy in environments that
have version 6 of the JRE. If you are developing for earlier versions of
the Java Platform, you must bundle the Swing Layout Extension Library
with the application. For more information,
see Deploying Java GUI Applications.
Guarded Blocks
As you work with a form in the Design view, code is generated automatically
by the GUI Builder and is displayed in the Source view
with a blue background. This code is called guarded text and is not directly
editable.
Guarded text generated by the GUI Builder's includes:
- Blocks of components' variable declarations.
- The initComponents() method, in which form initialization
is performed. This method is called from the form's constructor and though
it is not editable manually, you can affect the way it is generated by editing
the Code properties in the component's property sheet.
- The header (and trailing brace) of all event handlers.
GUI Form Hierarchy in the IDE
The IDE's Inspector window provides a hierarchical tree view of the form's various components.
Each form is represented by a root node (
)
within which all components in the form's class
are contained. All other GUI components are organized into one of the following
two subnodes:
- Form Container node (
).
Represents the top level of the form's hierarchy and contains the visible
components currently displayed in the GUI Builder.
- Other Components node (
).
Contains the form's non-visual components.
Notes:
- To use the GUI Builder, you must work with
files that were created with the IDE's GUI form templates. You cannot use
the GUI Builder to edit GUI forms that were created outside of the IDE.
- You can combine FreeDesign containers and containers using other layout
managers together in the same form.
- Forms created in earlier versions of the IDE are not automatically converted to
the FreeDesign layout manager and remain editable in the same way as before.
- New containers added to forms created in earlier versions of the IDE
do not assume the FreeDesign layout manager in order to ensure code compatibility.
However, you can set it manually in the Set Layout submenu.
- See Also
- Creating a New Form
- About Layout Managers
- Deploying Java GUI Applications
Legal Notices