Java IntelliJ GUI app notes
Table of Contents
Issues in building a GUI app
gwideman, Jun 1, 2012 12:22 am
gwideman, Jun 3, 2012 12:33 am
This page captures some notes on how to create a GUI app in IntelliJ IDEA. Applies to IDEA 11.1.2
Assuming that IntelliJ IDEA is installed...
Documentation is kind of disjointed
GUI Designer: doc for settings for GUI Designer
GUI Designer Basics
Designing GUI. Major Steps
Creating and Opening Forms
"On the main menu, choose
Edit | New"
But there is no New on the Edit menu. Stuck.
If instead I use the usual Add Module dialog, it doesn't offer GUI Form.
... says to make sure UI Designer is enabled in Settings > Plugins. OK, it is enabled.
(allows positioning and rewinding better)
Or save that file, then use Moyea swf2video to convert to mp4, so that VLC can play it, with sufficient control over forward, reverse and replay to make this video useful. Sigh.
"For IntelliJ IDEA 6.0" (so how applicable is it to 11.1.x? Looks like some translation is needed)
Demo is based on the JGoodies layout manager and JGoodies Forms. Is JGoodies included with IDEA? If not, what needs to be installed?
Ah, video says JGoodies is included
UI Designer also supports Swing components
From video, IDEA 6 style:
Project Settings > Select Project (or module?) > Classpath tab, (then hit +?), then browse to folder where jar is located
Shown as: C:\Demetra\lib\jgoodies-forms.jar
New package: com.intellij.yourappname
On that package, right-click > New > GUI something (off screen)
Translation to IDEA 11.x
In Project window
Tell project about jgoodies-forms:
Right-click on top-level "module" (aka Project) > Project Structure dialog
Libraries > [+] > Java > ... Select Library Files.
C:\Program Files (x86)\JetBrains\IntelliJIDEA11.1.1\lib\jgoodies-forms.jar
I notice there are other jgoodies jars that might be needed?
Interposing a package
(tree of directories) at this stage is optional.
Create a module:
Top module (or package if you created one) > Right-click > New Module (MyApp01)
Add jgoodies dependency to new module:
MyApp01 > right-click > Open Module Settings
Select the module (MyApp01), Dependencies > [+] > Libraries > select jgoodies-forms
Create new Form class:
MyApp01/src > right-click > New > GUI Form
Form name: MyMainForm; Base layout manager > Form Layout (JGoodies); [x] Create bound class; Class name MyMainForm
GUI designer appears.
Rest of video pretty much corresponds to experience in IDEA 11.x
Issues in building a GUI app
: In the following, assume the form class is called MyForm.
Understanding the form initialization sequence.
Change File > Settings > GUI Designer >Generate GUI into Java source code, so that the complete initialization code is visible for inspection.
GUI Designer's main initialization code is in $$$setupUI$$$(), and a call to that method is inserted either at the beginning of the constructor, or into an initializer block. (Rarely used Java syntax: method without name or arguments, just a block, with in this case a call to $$$setupUI$$$(). )
So, all Designer-managed components are instantiated before any developer's code runs, even code in the MyForm constructor.
: This method is for custom constructing components that have been laid out in the Designer, and have Custom Create set true.
This method is called from $$$setupUI$$$(). The line of code for the call is only generated if there are any components with Custom Create checked. That call is placed first in $$$setupUI$$$().
Do not place any other custom component creation (such as menus) in createUIComponents(), because that method doesn't get called if no components have Custom Create checked.
: Although IDEA has a graphical designer for laying out forms, it doesn't provide any IDE support for menus. Menus have to be built by manually typing in code to create JMenuBar/JMenu/JMenuItem (etc) code including event handlers. That could follow standard Swing tutorials and practice, but you have to figure out how to reconcile the structure and sequence of UI-construction/initialization code in the tutorials versus the structure IDEA builds from the form designer.
If you use Alt-Ins to create the default class static main(), the generated code constructs the top-level JFrame, instance of MyForm
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world
Turn off "Getting Started"