Netbeans FormDesigner的确非常的强大。我现在的一个Swing项目采取的开发方法是,使用netbeans的form designer设计界面。当然设计出来的界面只包含组件的定义。也就相当于MVC的View,所有控制类放到一个Controller里面。

要快速上手Form Desinger的方法就是要学会看懂它的.form文件。这个文件是xml格式的,因此非常容易懂。

一般的格式都是这样的,先定义布局。例如GridLayout ,2行1列

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">

    <Property name="columns" type="int" value="1"/>

    <Property name="horizontalGap" type="int" value="5"/>

    <Property name="rows" type="int" value="2"/>

    <Property name="verticalGap" type="int" value="5"/>

  </Layout>

包含两个用于布局的panel

  <SubComponents>

    <Container class="javax.swing.JPanel" name="aliasPnl">

      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">

        <Property name="columns" type="int" value="2"/>

        <Property name="rows" type="int" value="1"/>

      </Layout>

      <SubComponents>

存放一个登陆用的下拉框

        <Component class="javax.swing.JLabel" name="loginAliasesLbl">

          <Properties>

            <Property name="horizontalAlignment" type="int" value="0"/>

            <Property name="text" type="java.lang.String" value="Choose Alias"/>

          </Properties>

        </Component>

        <Component class="javax.swing.JComboBox" name="loginAliasesCbo">

        </Component>

      </SubComponents>

    </Container>

    <Container class="javax.swing.JPanel" name="buttonPnl">

      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">

        <Property name="columns" type="int" value="3"/>

        <Property name="horizontalGap" type="int" value="5"/>

        <Property name="rows" type="int" value="1"/>

        <Property name="verticalGap" type="int" value="5"/>

      </Layout>

三个按钮并排放

      <SubComponents>

        <Component class="javax.swing.JButton" name="manageBtn">

          <Properties>

            <Property name="mnemonic" type="int" value="109"/>

            <Property name="text" type="java.lang.String" value="Manage a/cs"/>

          </Properties>

        </Component>

        <Component class="javax.swing.JButton" name="loginBtn">

          <Properties>

            <Property name="mnemonic" type="int" value="108"/>

            <Property name="text" type="java.lang.String" value="Login"/>

          </Properties>

        </Component>

        <Component class="javax.swing.JButton" name="cancelBtn">

          <Properties>

            <Property name="mnemonic" type="int" value="99"/>

            <Property name="text" type="java.lang.String" value="Cancel"/>

          </Properties>

        </Component>

      </SubComponents>

    </Container>

  </SubComponents>

把这个文件摸透以后,在来使用GUI就直观多了,按照左下角的导航栏来设计模块的包含非常的简单。

这个世界上的GUI IDE有两种逻辑,一种是把事情做好。不管花什么代价。另一种是代价要最小,不管东西好不好,能用就行。

Swing是前者。VB是后者