How do I create a new Swing app in IntelliJ IDEA Community edition?
The following instruction applies to IntelliJ Idea 14.
- Enable UI Designer
- File → Settings → Plugins → UI Designer
- Enable generate Java class
- File → Settings → Editor → GUI Designer → change Generate GUI into “Java source code”
- Go to the project view, and right click the package name where you want the generated Java class to be stored
- On the context menu, choose New → GUI Form, and set the bound class
- In the designer, it will automatically put a Jpanel on the window. Choose Jpanel, and first set the Layout manager to GridLayoutManager(IntelliJ).
- Adding components as needed, make sure to give some value to “field name”. This value will become the name of this component in the form class.
- You can preview the form by right click and then choose preview.
- When you are done, change the layout manager for Jpanel to “GridBagLayout”.
- Click on Build → Make Project to generate Java source codes and store them in the bound Java class.
Creating a New GUI Form or Dialog
To create a new GUI form
1.On the main menu, choose File | New, as described in the section Creating Files.
2.On the pop-up menu, choose GUI Form.
3.Specify the name of the new form, and select the layout manager.
4.Check the option Create bound class, and specify the bound class name.
5.Click OK.
To create a new dialog
1.On the main menu, choose File | New, as described in the section Creating Files.
2.On the pop-up menu, choose Dialog.
3.Specify the name of the new dialog.
4.Specify the following options:
Generate main() method that creates and shows dialog.
Generate OK handler.
Generate Cancel handler.
5.Click OK.
To create a File Template from a GUI form
1.Create a GUI form or open it in the GUI Designer.
2.On the Main menu, choose Tools | Save File as Template. The File Templates dialog displays the source code of the form. The extension of the new template is .form 3.Specify the template name, and click OK.
To create a new GUI form from a File Template
1.In the Project tool window, right-click the package where you want to create the new form. 2.On the context menu choose New. The submenu contains items for all defined File Templates, including GUI forms. 3.Select the desired GUI form template on the context menu, and give it a name when prompted.
Creating Snapshots
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
1.Open the module that contains source code for the dialog you want to capture.
2.Select the Application Run Configuration, make sure that the option Enable capturing form snapshots is checked, and run the application.
3.In the running application, perform whatever interaction is necessary to open the dialog you want to capture.
4.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: enter image description here
The Create Form Snapshot dialog box appears.
5.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. enter image description here
Opening Existing GUI Forms
1.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:
-Double-click.
-Choose Jump to Source on the context menu.
-Press F4.
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.
IntelliJ IDEA is first of all a very smart editor, not a RAD tool like Delphi.
However, it has a powerful gui editor - just right click on any package in the Project view on the left, and select New GUI form
or New Dialog
, and it will let you create GUI. This question provides more info about running the gui.
There is no such thing as GUI project in IDEA. You can add GUI forms there at any time you need, just by RightClick -> New -> GUI Form. You can create GUI app from it just by adding main()
method into the form binding class. IDEA does the job for you if you hit Alt-Ins (or menu Code->Generate) when in the binding class editor. The only requirement for this is to place correct name for the form's root panel.
You also should check this manual to discover some other things: https://www.jetbrains.com/help/idea/designing-gui-major-steps.html. Anyway, the GUI builder is pretty intuitive.