178 lines
7.4 KiB
Plaintext
178 lines
7.4 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy for HTML5 for Apple macOS version 5.8.0">
|
|
<title>Using the NetBeans Swing GUI Builder</title>
|
|
<meta name="author" content="Bob Jacobsen">
|
|
<meta name="keywords" content="JMRI technical code NetBeans GUI">
|
|
<!--#include virtual="/help/en/parts/Style.shtml" -->
|
|
</head>
|
|
<body>
|
|
<!--#include virtual="/help/en/parts/Header.shtml" -->
|
|
|
|
<div id="mBody">
|
|
<!--#include virtual="Sidebar.shtml" -->
|
|
|
|
<div id="mainContent">
|
|
<h1>JMRI Code: Using the NetBeans Swing GUI Builder</h1>
|
|
<!-- - - - - - - - - -->
|
|
|
|
<p>Portions of the JMRI Graphical User Interface (GUI) code are maintained using the <a href=
|
|
"https://netbeans.org/features/java/swing.html">NetBeans Swing GUI Builder</a> (the
|
|
"Builder"). This page is a guide to using the Builder tool. See <a href=
|
|
"NetBeans.shtml">Building with NetBeans</a> for a general introduction to using NetBeans for
|
|
maintaining JMRI.</p>
|
|
<!-- - - - - - - - - -->
|
|
|
|
<ul>
|
|
<li>
|
|
<a href="#intro">Introduction</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="#usage">Using the Builder</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="#code">Examining the Code</a>
|
|
<ul>
|
|
<li>
|
|
<a href="#java">.java File</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="#form">.form File</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="#references">See Also</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<h2 id="intro">Introduction</h2>
|
|
|
|
<p>NetBeans 7.4 or 8.0 includes a Swing GUI Builder that makes it easier to maintain a Java
|
|
Swing-based GUI (such as JMRI) than writing the user interface entirely by hand.</p>
|
|
|
|
<p>This tool can create code that is not ideally separated into human-maintained and
|
|
generated Java code. If you use NetBeans, you are protected from this, as the Builder does a
|
|
good job of integrating its views with the source editor. However, if you use another editor,
|
|
you will be exposed to this.</p>
|
|
|
|
<h2 id="usage">Using the Builder</h2>
|
|
|
|
<p>The NetBeans IDE editor toolbar will automatically contain a button labeled
|
|
<strong>Design</strong> if the Class being edited can also be edited in the Swing GUI
|
|
Builder.</p>
|
|
|
|
<p>Clicking the <strong>Design</strong> button will present the ability to drag buttons,
|
|
labels, panels, and other objects onto a window to visually place them. Any object that
|
|
conforms to the <a href=
|
|
"http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html">JavaBean</a>
|
|
standard can be placed on the window and linked to other objects on the window, even if it
|
|
does not have a visual representation.</p>
|
|
|
|
<p>Where the Builder cannot automatically generate code, it provides empty, or stub, methods
|
|
that can be completed to implement the desired logic, and will automatically switch to the
|
|
code view as needed.</p>
|
|
|
|
<h2 id="code">Examining the Code</h2>
|
|
|
|
<p>The Builder maintains two files: a .java file, containing compilable code, and a .form
|
|
file, containing an XML representation of GUI along with code that is used to create the
|
|
initComponents() method in the .java file.</p>
|
|
|
|
<h3><a href="java">.java File</a>
|
|
</h3>
|
|
|
|
<p>In NetBeans, the code generated by the Builder, looks just like any other Java code,
|
|
although portions of it cannot be edited (NetBeans simply does not allow the code to be
|
|
changed). Stub methods will be editable, however, it will not be possible to change the
|
|
method signatures (name, parameters, return values, or throws clauses).</p>
|
|
|
|
<p>A method, <code>private void initComponents()</code></p>
|
|
|
|
<p>Other tools, however, will display the code very differently, and the code will contain
|
|
the following non-standard, though valid, markings as comments that are hidden in
|
|
NetBeans:</p>
|
|
|
|
<dl>
|
|
<dt>// <editor-fold defaultstate="collapsed" desc="Generated Code"></dt>
|
|
|
|
<dd>Hides everything between it and <code>// </editor-fold></code> with the
|
|
description <em>Generated Code</em> in NetBeans and other editors that recognize it. Code
|
|
between these two comments can be viewed by clicking the <strong>+</strong> icon to the
|
|
left of the description in those editors. It is used to hide code that should not be edited
|
|
by hand.</dd>
|
|
|
|
<dt>// </editor-fold></dt>
|
|
|
|
<dd>Used with <code>// <editor-fold defaultstate="collapsed" desc="Generated
|
|
Code"></code>. See that comment's description for more information.</dd>
|
|
|
|
<dt>//GEN-BEGIN:<em><token></em></dt>
|
|
|
|
<dd>Precedes a method or block of variables that is completely generated by the Builder.
|
|
Such a method or block is followed by a corresponding
|
|
<code>//GEN-END:<em><token></em></code> comment.</dd>
|
|
|
|
<dt>//GEN-END:<em><token></em></dt>
|
|
|
|
<dd>Follows a method or block of variables that is completely generated by the Builder.
|
|
Such a method or block is preceded by a corresponding
|
|
<code>//GEN-BEGIN:<em><token></em></code> comment.</dd>
|
|
|
|
<dt>//GEN-FIRST:<em><token></em></dt>
|
|
|
|
<dd>Precedes a method that generated code calls, but the body of which is written by a
|
|
developer. Such a method is followed by a corresponding
|
|
<code>//GEN-LAST:<em><token></em></code> comment. The token is often
|
|
<code>event_<em><methodName></em></code>.</dd>
|
|
|
|
<dt>//GEN-LAST:<em><token></em></dt>
|
|
|
|
<dd>Follows a method that generated code calls, but the body of which is written by a
|
|
developer. This comment marks the closing curly brace in the method preceded by the
|
|
corresponding <code>//GEN-FIRST:<em><token></em></code> comment.</dd>
|
|
</dl>
|
|
|
|
<h3><a href="form">.form File</a>
|
|
</h3>
|
|
|
|
<p>The .form file is completely hidden within the NetBeans IDE. Opening a .java file with a
|
|
corresponding .form file (the same file name in the same package) will add the
|
|
<strong>Design</strong> button to the editor tool bar, allowing the Builder to be used.</p>
|
|
|
|
<p>The .form file is an XML file adhering to the DTD in <a href=
|
|
"http://hg.netbeans.org/core-main/file/tip/form/src/org/netbeans/modules/form/forminfo/forms.dtd">
|
|
the NetBeans source code</a> (linked to the head of the NetBeans trunk). NetBeans uses this
|
|
file to store additional information outside the JavaBeans specification that is required to
|
|
correctly generate the <code>initComponents()</code> method, stub methods, and variable
|
|
lists. In the absence of other changes to the .java file, this file could be used to
|
|
completely generate a new .java file, should that be necessary.</p>
|
|
|
|
<p>This file should not be edited by hand, but should be generated by the Builder.</p>
|
|
|
|
<h2 id="references">See Also</h2>
|
|
|
|
<ul>
|
|
<li>
|
|
<a href="https://netbeans.org/kb/docs/java/quickstart-gui.html">Designing a Swing GUI in
|
|
NetBeans IDE</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="https://netbeans.org/kb/trails/matisse.html">Java GUI Applications Learning
|
|
Trail</a>
|
|
</li>
|
|
</ul>
|
|
<!--#include virtual="/help/en/parts/Footer.shtml" -->
|
|
</div>
|
|
<!-- closes #mainContent-->
|
|
</div>
|
|
<script src="/js/help.js"></script>
|
|
</body>
|
|
</html>
|