Swing GUI Designer
It is highly recommended that you view the GUI designer demo before reading this section. The demo shows how to create a form using the JGoodies layout manager, quickly add listeners, navigate between the form and Java code, internationalize UI, and migrate hand-written UI or forms created in other UI designers to IntelliJ IDEA's GUI designer. Swing GUI Designer Live Demo
Visual editor for creating and modifying forms
A rich set of visual form-building tools is incorporated into a convenient editor pane. With the help of an intuitive user interface, you can quickly learn and start using the GUI Designer. Even complex GUI forms can be easily created from scratch. Moreover, re-arranging, adding or deleting GUI components do not break the form layout and are conveniently handled.
Automated management of Grid layouts
IntelliJ IDEA new innovative GUI designer uses a grid paradigm for the quick and easy creating and maintenance of both complex and simple component layouts. The following Grid layout managers are supported:
- IntelliJ GridLayoutManager
- JGoodies Forms
You can choose different layout managers for each panel on the form, or define the default manager. Whenever you drop a component on the form, the corresponding Grid element is created automatically. Grid cells are created and even deleted according to your actions, exactly at the time it is necessary. Of course you are free to manage Grid elements yourself, including rearrangement of Grid rows and columns with a simple drag & drop.
JGoodies Forms support
Among other Grid layout managers, IntelliJ IDEA supports JGoodies Forms. It provides you with automatic inserting and deleting of gap rows and columns, allows you to edit FormLayout-specific properties by simply selecting the caption of the corresponding column or row, and enables of grouping rows or columns to keep their size equal. One more important feature is an ability to convert forms designed using other layout managers to JGoodies Forms.
Migrating the hand-coded GUI and forms created in other designers
IntelliJ IDEA allows you to easily convert both hand-coded GUI and forms created in other designers to its GUI designer format. You can migrate an entire dialog form or any part of it. Either way, IntelliJ IDEA preserves both layout and component properties.
Fully keyboard accessible features
Keeping with its famous keyboard-centric approach, IntelliJ IDEA enables you to use the keyboard to edit layouts, select, add, move, resize components, and perform other essential actions. Of course, everything can also be done with the mouse.
Accelerating standard actions
With IntelliJ IDEA you can quickly perform the actions that are common to any process of Swing interface design, including:
- Surround With (Ctrl+Alt+T) — wrap/unwrap selected components in a JPanel, JScrollPane, etc.
- Duplicate (Ctrl+D) — create a copy of the selected components in the next row
- Morph (available from the shortcut menu) — convert a component to a different class, while preserving its properties
Also you can quickly generate the main() method to make the form run (Alt + Insert in the class bound to the form).
Separating GUI layout from code
GUI layout information is separated from your Java code and is stored in devoted XML-based form files. Each GUI form is bound to a Java class, and form components are referred by class fields.
Unique Byte-code instrumentation techniques allow you to get rid of complicated Swing code in your Java sources. IntelliJ IDEA's GUI-compiler transparently generates all necessary code needed to create and lay out form components. The GUI-compiler has been integrated into IntelliJ IDEA's make functionality, and is also available as a separate Ant task delivered together with the IntelliJ IDEA distribution. There is also an option to generate Java source code instead of using the byte-code instrumentation approach.
Auto-generating the field names
When you add a component to a GUI form, IntelliJ IDEA automatically generates a corresponding field in the class to which the form is bound, and names the field according to the component�s name or the text of an assigned label. For example, if you have a list component with an assigned label, and the label text is "Font name", the name of the list will be "fontNameList". You are free to change the default name anytime.
Quick creating of listeners
You can quickly add listeners to components right from UI designer — just press Ctrl + O on the selected component and select the necessary listener. The anonymous listener class will be generated in the bound GUI class.
Easy navigation between GUI designer and Java code
You can quickly navigate from any component in the GUI Designer to the corresponding listener (if any) by pressing Ctrl + Alt + B. To navigate back to the GUI Designer, click the icon next to a field that is bound to some UI component.
Code inspections and quick fixes right in GUI designer
Unique IntelliJ IDEA engine for code analysis and inspection is also integrated with the GUI designer. If the UI component does not meet the inspection rules, it is highlighted in the designer component tree, and intelligent quick fixes help you to instantly solve discovered problems. With code inspections you can quickly discover the following problems:
- Missing or duplicated mnemonic
- Radio button not in a group
- Radio button group with one button
- No label for component
- Scrollable component is not in a ScrollPane
- Assignment to UI-bound field in Java code
GUI internationalization and localization
Text values on GUI components can be specified either by constant strings, or be obtained from the specified resource bundle. You can create and maintain "i18n" property files and keys directly from the GUI designer. The designer highlights hard-coded String literals, and provides
intention actions with Quick Fixes enabling you to quickly replace them with property keys, or mark them as not requiring internationalization.
Switching locale at the design time
When you have multiple localizations for a GUI form, you can switch locales with a single click to see how any variant looks at design time.
Quick mnemonics assignment
You can quickly assign mnemonics the components that can get focus at runtime (such as buttons, lists, etc.) Just press Alt + Enter on the component either in the GUI form or in the component tree. IntelliJ IDEA will suggest a mnemonic character smartly avoiding mnemonics duplicates. If you have incidentally assigned the same mnemonics to different components, IntelliJ IDEA will notify you about that and suggest fixing the problem.
Ability to create custom palettes
You can extend the default Swing palette with the following elements:
- Custom UI beans
- UI beans from one or more third-party libraries
- Custom containers
- "Nested forms" — forms that can be inserted into other forms
Fast & easy data-binding
When you are done with the GUI layout, a unique data-binding wizard will help you quickly bind the GUI components with the data fields of your Java beans. You are also able to opt for automatic generation of get(), set() and isChanged() methods for the data fields.
Native Ant task for compiling GUI forms into your builds
The bundled Ant task supports byte-code instrumentation techniques for compiling IntelliJ IDEA GUI forms. It provides the following benefits:
- You can quickly integrate the generated GUI forms into your project build
- Use of GUI designer does not force you to keep all of your coding in IntelliJ IDEA (especially useful when team members work with different IDEs).