Java Reference
In-Depth Information
10.7.1
Generating the GUI to binary or source
When you make your project, IDEA adds the necessary code to create and initial-
ize the forms that make up your project with their respective classes. Normally
this is all transparent to you. IDEA modifies your source code on the fly, compiling
in the changes silently. If you wish, you can disable this behavior through the GUI
Designer settings panel by switching the Generate GUI to option to Java source
code. If you do this, you'll see the generated source code added to the form class
in a method called $$$setupUI$$$() . A call to this method is also added to the
constructor. However, you aren't allowed to edit this code or call the setup
method yourself. This method is regenerated each time you build the project as
the form XML file is processed.
Why would anyone want to generate Java source and compile the class by hand
when IDEA 's build system handles the process invisibly for you? The only reason to
expose the generated source is to export the source code out of IDEA , to eliminate
any dependence on IDEA . If you have a team of developers, some of whom don't
use IDEA , you probably shouldn't store form files to define your user interfaces. If
you do, only the developers using IDEA will be able to edit those GUI s. Any changes
made to the $$$setupUI$$$() method by non- IDEA developers will be overridden
the next time someone runs a Make Project command. In this situation, you could
design your form in the GUI Designer, build it to Java source, and then refactor the
content out of $$$setupUI$$$() into other methods, like the class constructor. You
could then discard the original form file and treat the form class as if you'd written
it by hand.
10.7.2
Including the forms library
When you create your user interface with IDEA 's GUI builder, you're using IDEA 's
custom layout classes and must include them with your application in order for
users to run it. When you build an application using the GUI Designer, IDEA auto-
matically copies a few files into your output folder under the com.intellij.uide-
signer.core package structure. That way, you can package up these classes along
with your own to ensure you application runs outside of IDEA .
You can disable this behavior through the GUI Designer settings panel by
deselecting the option to automatically copy the form classes to the output direc-
tory. If you do so, you still need to distribute the classes. These classes are
included in a JAR file located in the redist folder (short for redistributable ) of your
IDEA installation. The name of the library is forms_rt.jar . Of course, you must
also add it to the Classpath when running your application.
 
 
 
 
 
 
 
Search WWH ::




Custom Search