Java Reference
In-Depth Information
10.2 Working with forms
Forms are stored as files in your project, just like Java files, images, HTML , and so
forth. You can access them through either the project or source code views. Cre-
ating or editing a form invokes the GUI Designer, as shown in figure 10.1. The
GUI Designer is just a different type of editor, so forms appear in the main editor
window of IDEA in their own tab, just as Java classes and other files do.
10.2.1
Creating a new form
The files that represent GUI forms, although not Java classes themselves, live in
the source tree of your module. Forms are stored on disk as files with the .form
extension but are really XML files that contain all the information about your
form (such as component definitions, and alignment and layout metadata). At
some point, IDEA must generate Java code from that XML definition and then
compile that generated source in order to run your GUI .
Creating a form is similar to creating a Java class. In the Project tool window,
choose the package where the form should reside, and then right-click that pack-
age and select New | GUI Form from the context menu. You're prompted for a
filename, and that form file is stored in that package. Like most other files, you
can move, copy, rename, and delete forms as necessary, although you should
never edit the XML in this file directly. These operations act like other refactor-
ings; IDEA smartly manages all the necessary references.
If you need to create a simple dialog, the New | Dialog command auto-
matically generates both the class and form stubs (including OK and
Cancel buttons) and their respective handlers, if you so choose.
TIP
10.2.2
Placing components into the workspace
The next step in designing a user interface form is to add your components to the
workspace and arrange them into a rough approximation of your desired layout.
Adding components to your design
To add a component to your form, first click an item from the component palette
on the Designer's toolbar. It's highlighted to show that it's selected. Next, move
your pointer into the design panel, and left-click to place the new component
(note that you don't drag items from the palette bar—you click to select and then
click to place them). When you're placing a component into your form, your
mouse pointer changes to indicate a valid placement. You can only place compo-
nents into the following areas:
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search