改变Swing unicenta opos的布局和首选尺寸

时间:2015-03-08 15:11:43

标签: java swing layout jpanel

如何更改布局管理器以及如何在更改其他组件时无需任何引用来调整任何组件的大小?

我正在使用unicenta 3.7源代码来修改JPanel Ticket,但是当我从属性中更改首选大小时,它会动态返回原始首选大小代码,所以:

我的问题是如何如何变换布局管理器以及如何使任何组件可以自由调整大小而无需任何参考更改其他组件,我觉得上图中的组件之间存在磁力,当您移动Jtext字段时受其影响的按钮

以下是Ticket

的图片

enter image description here

这是源代码面板Ticket.form

<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
  <Properties>
    <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
      <Color blue="99" green="cc" red="ff" type="rgb"/>
    </Property>
  </Properties>
  <AuxValues>
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-24,0,0,3,17"/>
  </AuxValues>

  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/>
  <SubComponents>
    <Container class="javax.swing.JPanel" name="m_jPanContainer">
      <Constraints>
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
          <CardConstraints cardName="ticket"/>
        </Constraint>
      </Constraints>

      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
      <SubComponents>
        <Container class="javax.swing.JPanel" name="m_jOptions">
          <Constraints>
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
              <BorderConstraints direction="North"/>
            </Constraint>
          </Constraints>

          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
          <SubComponents>
            <Container class="javax.swing.JPanel" name="m_jButtons">
              <Constraints>
                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
                  <BorderConstraints direction="Before"/>
                </Constraint>
              </Constraints>

              <Layout>
                <DimensionLayout dim="0">
                  <Group type="103" groupAlignment="0" attributes="0">
                      <Group type="102" alignment="0" attributes="0">
                          <EmptySpace min="5" pref="5" max="-2" attributes="0"/>
                          <Component id="jButton1" min="-2" max="-2" attributes="0"/>
                          <EmptySpace max="32767" attributes="0"/>
                          <Component id="btnCustomer" min="-2" max="-2" attributes="0"/>
                          <EmptySpace max="32767" attributes="0"/>
                          <Component id="btnSplit" min="-2" max="-2" attributes="0"/>
                          <EmptySpace max="32767" attributes="0"/>
                      </Group>
                  </Group>
                </DimensionLayout>
                <DimensionLayout dim="1">
                  <Group type="103" groupAlignment="0" attributes="0">
                      <Group type="102" attributes="0">
                          <EmptySpace min="5" pref="5" max="-2" attributes="0"/>
                          <Group type="103" groupAlignment="0" attributes="0">
                              <Component id="jButton1" min="-2" max="-2" attributes="0"/>
                              <Component id="btnCustomer" min="-2" max="-2" attributes="0"/>
                              <Component id="btnSplit" min="-2" max="-2" attributes="0"/>
                          </Group>
                          <EmptySpace min="-2" pref="5" max="-2" attributes="0"/>
                      </Group>
                  </Group>
                </DimensionLayout>
              </Layout>
              <SubComponents>
                <Component class="javax.swing.JButton" name="jButton1">
                  <Properties>
                    <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
                      <Image iconType="3" name="/com/openbravo/images/customer_add_sml.png"/>
                    </Property>
                    <Property name="toolTipText" type="java.lang.String" value="Add New Customer"/>
                    <Property name="focusPainted" type="boolean" value="false"/>
                    <Property name="focusable" type="boolean" value="false"/>
                    <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                      <Insets value="[0, 4, 0, 4]"/>
                    </Property>
                    <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="requestFocusEnabled" type="boolean" value="false"/>
                  </Properties>
                  <Events>
                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
                  </Events>
                </Component>
                <Component class="javax.swing.JButton" name="btnCustomer">
                  <Properties>
                    <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
                      <Image iconType="3" name="/com/openbravo/images/customer_sml.png"/>
                    </Property>
                    <Property name="toolTipText" type="java.lang.String" value="Show Customers"/>
                    <Property name="focusPainted" type="boolean" value="false"/>
                    <Property name="focusable" type="boolean" value="false"/>
                    <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                      <Insets value="[0, 4, 0, 4]"/>
                    </Property>
                    <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="requestFocusEnabled" type="boolean" value="false"/>
                  </Properties>
                  <Events>
                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCustomerActionPerformed"/>
                  </Events>
                </Component>
                <Component class="javax.swing.JButton" name="btnSplit">
                  <Properties>
                    <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
                      <Image iconType="3" name="/com/openbravo/images/sale_split_sml.png"/>
                    </Property>
                    <Property name="toolTipText" type="java.lang.String" value="Split Sale"/>
                    <Property name="focusPainted" type="boolean" value="false"/>
                    <Property name="focusable" type="boolean" value="false"/>
                    <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                      <Insets value="[0, 4, 0, 4]"/>
                    </Property>
                    <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                      <Dimension value="[50, 40]"/>
                    </Property>
                    <Property name="requestFocusEnabled" type="boolean" value="false"/>
                  </Properties>
                  <Events>
                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSplitActionPerformed"/>
                  </Events>
                </Component>
              </SubComponents>
            </Container>
            <Container class="javax.swing.JPanel" name="m_jPanelScripts">
              <Constraints>
                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
                  <BorderConstraints direction="After"/>
                </Constraint>
              </Constraints>

              <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
              <SubComponents>
                <Container class="javax.swing.JPanel" name="m_jButtonsExt">
                  <Constraints>
                    <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
                      <BorderConstraints direction="After"/>
                    </Constraint>
                  </Constraints>

                  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
                  <SubComponents>
                    <Container class="javax.swing.JPanel" name="jPanel1">
                      <Properties>
                        <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                          <Dimension value="[235, 50]"/>
                        </Property>
                      </Properties>

                      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
                      <SubComponents>
                        <Component class="javax.swing.JButton" name="m_jbtnScale">
                          <Properties>
                            <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
                              <Font name="Arial" size="11" style="0"/>
                            </Property>
                            <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
                              <Image iconType="3" name="/com/openbravo/images/scale.png"/>
                            </Property>
                            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
                              <ResourceString bundle="pos_messages.properties" key="button.scale" replaceFormat="AppLocal.getIntString(&quot;{key}&quot;)"/>
                            </Property>
                            <Property name="toolTipText" type="java.lang.String" value="Scale"/>
                            <Property name="focusPainted" type="boolean" value="false"/>
                            <Property name="focusable" type="boolean" value="false"/>
                            <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                              <Insets value="[8, 14, 8, 14]"/>
                            </Property>
                            <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[85, 44]"/>
                            </Property>
                            <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[85, 44]"/>
                            </Property>
                            <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[85, 40]"/>
                            </Property>
                            <Property name="requestFocusEnabled" type="boolean" value="false"/>
                          </Properties>
                          <Events>
                            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="m_jbtnScaleActionPerformed"/>
                          </Events>
                        </Component>
                        <Component class="javax.swing.JButton" name="jbtnMooring">
                          <Properties>
                            <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
                              <Font name="Arial" size="11" style="0"/>
                            </Property>
                            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
                              <ResourceString bundle="pos_messages.properties" key="button.moorings" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
                            </Property>
                            <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                              <Insets value="[8, 14, 8, 14]"/>
                            </Property>
                            <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[80, 40]"/>
                            </Property>
                            <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[80, 40]"/>
                            </Property>
                            <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[80, 40]"/>
                            </Property>
                          </Properties>
                          <Events>
                            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jbtnMooringActionPerformed"/>
                          </Events>
                        </Component>
                        <Component class="javax.swing.JButton" name="j_btnKitchenPrt">
                          <Properties>
                            <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
                              <Image iconType="3" name="/com/openbravo/images/printer24.png"/>
                            </Property>
                            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
                              <ResourceString bundle="pos_messages.properties" key="button.sendorder" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
                            </Property>
                            <Property name="toolTipText" type="java.lang.String" value="Send to Kichen Printer"/>
                            <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
                              <Insets value="[0, 4, 0, 4]"/>
                            </Property>
                            <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[50, 40]"/>
                            </Property>
                            <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[50, 40]"/>
                            </Property>
                            <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                              <Dimension value="[50, 40]"/>
                            </Property>
                          </Properties>
                          <Events>
                            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="j_btnKitchenPrtActionPerformed"/>
                          </Events>
                        </Component>
                      </SubComponents>
                    </Container>
                  </SubComponents>
                </Container>
              </SubComponents>
            </Container>
            <Container class="javax.swing.JPanel" name="m_jPanelBag">
              <Properties>
                <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
                  <Dimension value="[0, 50]"/>
                </Property>
              </Properties>
              <Constraints>
                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
                  <BorderConstraints direction="Center"/>
                </Constraint>
              </Constraints>

              <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
            </Container>
          </SubComponents>
        </Container>
        <Container class="javax.swing.JPanel" name="m_jPanTicket">
          <Properties>
            <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
              <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
                <EmptyBorder bottom="5" left="5" right="5" top="5"/>
              </Border>
            </Property>
          </Properties>
          <Constraints>
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
              <BorderConstraints direction="Center"/>
            </Constraint>
          </Constraints>

1 个答案:

答案 0 :(得分:0)

你会发现控件之间的差距只需双击它并使其可调整大小,以便能够移动控件而不调整其他控件的大小,而是间隙将调整大小