Creating and Opening Forms
GUI Designer equips the developers with the possibility to create GUI forms with the desired layout and bound class, and dialogs. A form can be created as only a form file, or together with a UI class. A dialog framework consists of a class defining basic components and methods, and a GUI form with components bound to the fields of the UI class.
Prior to creating GUI forms and dialogs, select a package where the forms will be stored. You might need to create a package first. It is recommended to store the forms and dialogs in the same package as the classes that implement their functionality.
Creating a New GUI Form or Dialog
To create a new GUI form
On the main menu, choose.
On the pop-up menu, choose GUI Form.
Specify the name of the new form, and select the layout manager.
Check the option Create bound class, and specify the bound class name.
To create a new dialog
On the main menu, choose.
On the pop-up menu, choose Dialog.
Specify the name of the new dialog.
- Specify the following options:
main()method that creates and shows dialog.
Generate OK handler.
Generate Cancel handler.
Creating a form from a File Template
You can save any form as a File Template, and thus preserve commonly needed dialogs or panes of controls for later reuse. For detailed information about creating and using File Templates, refer to the sections:
To create a File Template from a GUI form
Create a GUI form or open it in the GUI Designer.
On the Main menu, choose File Templates dialog displays the source code of the form. The extension of the new template is .form. The
Specify the template name, and click OK.
To create a new GUI form from a File Template
In the Project tool window, right-click the package where you want to create the new form.
On the context menu choose New. The submenu contains items for all defined File Templates, including GUI forms.
Select the desired GUI form template on the context menu, and give it a name when prompted.
The Snapshot feature enables you to convert GUI forms created by some other means into IntelliJ IDEA GUI Designer Forms. All you need to do is run your application and save a part of the running application's component tree as a GUI Designer form. From then on, you can use the GUI Designer to extend or modify the form.
You can work with the layout and code in the GUI Designer just as you do with Forms originally created with the GUI Designer.
To take a Snapshot of an existing dialog
Open the module that contains source code for the dialog you want to capture.
In the running application, perform whatever interaction is necessary to open the dialog you want to capture.
- In the Project tool window, right-click the target package and choose New | Form Snapshot on the context menu. If the application is not yet running, IntelliJ IDEA prompts you to run it, and then prepare the application for taking snapshot:
The Create Form Snapshot dialog box appears.
- In the IntelliJ IDEA's Create Form Snapshot dialog, select the top-level component to be included in the snapshot, enter the form name, and click Create Snapshot button. The new form created this way is not bound to any class. You have to bind it to a class yourself.
Opening Existing GUI Forms
Open form files the same way you open source code or text files for editing. Locate the file in the appropriate navigation view, select it, and do one of the following:
Choose Jump to Source on the context menu.
Each form opens in a separate tab in the same space occupied by the Editor for source code files. You can have source code/text files and form files open simultaneously.