Java GridBagLayout的Swing错误

Java GridBagLayout的Swing错误,java,swing,gridbaglayout,Java,Swing,Gridbaglayout,我正在使用gridbag布局管理器编写一个多客户端对话框,当我试图运行这个程序时,它向我显示了一些我从未遇到过的奇怪错误 public class MultiEntryDlg extends JDialog { private static final long serialVersionUID = 1L; private final JPanel contentPanel = new JPanel() ; private DButton

我正在使用gridbag布局管理器编写一个多客户端对话框,当我试图运行这个程序时,它向我显示了一些我从未遇到过的奇怪错误

 public class MultiEntryDlg extends JDialog {
    private static final long serialVersionUID = 1L;
   private final JPanel             contentPanel    = new JPanel() ;
   private DButton          pb_OK                   = null ;  
   private DButton          pb_CANCEL               = null ;  
   private JLabel           lb_Name                 = null ;
   private JTextField       ef_name                 = null ;
   private JLabel           lb_taxonomyValue        = null;
   private JTextField       ef_taxonomyValue        = null ;
   private JLabel           lb_subscriptionKey      = null ;
   private JTextField       ef_subscriptionKey      = null ;
   private JCheckBox        cb_subscribable         = null ;
   private JTextField       ef_alias                = null ;
   private JLabel           lb_alias                = null ;
   private JLabel           lb_orderNumber          = null ;
   private JTextField       ef_orderNum             = null ;
   private JTextAreaCounter mle_DESCRIPTION_COUNTER = null ;               
   private SpellCheckPanel  spellCheckPanel         = null ;
   private JLabel    lb_contentLocation             = null ;
   private JComboBox contentlocCombo                = null ;
   private JLabel    lb_brandSubGrp                 = null ;
   private JComboBox brandSubGrpCombo               = null ;
   private JLabel    lb_fixedLocation               = null ;
   private JComboBox fixedlocCombo                  = null ;
   private JLabel    lb_taxonomyType                = null ;
   private JComboBox taxonomyCombo                  = null ;
   private NoTabJTextArea mle_DESCRIPTION           = null ;

   private MultiEntryDlg(){
       creatAndShowGUI();
   }

   public void actionPerformed ( ActionEvent e ) {

      if ( ( e.getSource() == pb_OK )
          dispose();
      else if (e.getSource() ==pb_CANCEL)
          dispose();
   }
   private void creatAndShowGUI(){
       initializeBasicProperty();
       addComponents();
   }

private void addComponents() {
    // TODO Auto-generated method stub
    lb_Name = new JLabel("Name (Max 75 char)");
    addLeftAlign(lb_Name, 0, 1);
    ef_name = new JTextField(10);
    addMergeColumn(ef_name, 1, 1, 2);
    spellCheckPanel = new SpellCheckPanel();
    spellCheckPanel.setTextComponent(ef_name);
    addCenterAlign(spellCheckPanel, 3, 1);
    lb_alias = new JLabel("Alias");
    addLeftAlign(lb_alias, 0, 2);
    ef_alias = new JTextField(10);
    addMergeColumn(ef_alias, 1, 2, 3);
    lb_orderNumber = new JLabel("Order Number");
    addLeftAlign(lb_orderNumber, 0, 3);
    ef_orderNum = new JTextField(10);
    addCenterAlign(ef_orderNum, 1, 3);
    lb_contentLocation = new JLabel("Content Location");
    addCenterAlign(lb_contentLocation, 2, 3);
    contentlocCombo = new JComboBox();
    addCenterAlign(contentlocCombo, 3, 3);
    lb_brandSubGrp = new JLabel("Brand Sub Group");
    addLeftAlign(lb_brandSubGrp, 0, 4);
    brandSubGrpCombo = new JComboBox();
    addCenterAlign(brandSubGrpCombo, 1, 4);
    lb_fixedLocation = new JLabel("Fixed Location");
    addLeftAlign(lb_fixedLocation, 2, 4);
    fixedlocCombo  = new JComboBox();
    addCenterAlign(fixedlocCombo, 3, 4);
    lb_taxonomyValue = new JLabel("Taxonomy Value");
    addLeftAlign(lb_taxonomyValue, 0, 5);
    ef_taxonomyValue = new JTextField(10);
    addCenterAlign(ef_taxonomyValue, 1, 5);
    lb_taxonomyType  = new JLabel ("Taxonomy Type");
    addLeftAlign(lb_taxonomyType, 2, 5);
    taxonomyCombo = new JComboBox();
    addCenterAlign(taxonomyCombo, 3, 5);
    cb_subscribable = new JCheckBox("Subscribable");
    addLeftAlign(cb_subscribable, 0, 6);
    lb_subscriptionKey = new JLabel("Subscription Key");
    addCenterAlign(lb_Name, 2, 6);
    ef_subscriptionKey = new JTextField(10);
    addCenterAlign(ef_subscriptionKey, 3, 6);
    addControlButton();
}

public static void main(String[] args) {
    try {
        MultiEntryDlg dialog = new MultiEntryDlg();
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void addControlButton() {
    // TODO Auto-generated method stub
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
    getContentPane().add(buttonPanel,BorderLayout.SOUTH);
    pb_OK = new DButton(Str.getStr(STR_OK));
    pb_CANCEL = new DButton(Str.getStr(STR_CANCEL));

    pb_OK.addActionListener(this);
    pb_CANCEL.addActionListener(this);

    buttonPanel.add(pb_OK);
    buttonPanel.add(pb_CANCEL);

}

private void addLeftAlign (Component component , int x, int y){
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(0, 0, 5, 5);
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = x;
    constraints.gridy = y;
    contentPanel.add(component, constraints);

}

private void addCenterAlign (Component component , int x ,int y){
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(0, 0, 5, 0);
    constraints.anchor = GridBagConstraints.HORIZONTAL;
    constraints.gridx = x;
    constraints.gridy = y;
    contentPanel.add(component, constraints);
}

private void addMergeColumn (Component component , int x, int y, int weight){
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(0, 0, 5, 5);
    constraints.anchor = GridBagConstraints.HORIZONTAL;
    constraints.gridx = x;
    constraints.gridy = y;
    constraints.gridwidth = weight;
    contentPanel.add(component, constraints);
}


private void initializeBasicProperty() {
    // TODO Auto-generated method stub
    setBounds(100, 100, 500, 250);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);    
    GridBagLayout gbl_contentPanel = new GridBagLayout();
    gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
    gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
    gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
    gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    contentPanel.setLayout(gbl_contentPanel);
}
} 
我得到以下错误

strArray in strObject is null. String Index:1  Language Ind:0
strArray in strObject is null. String Index:2  Language Ind:0
Exception in thread "main" java.lang.StackOverflowError
at com.ibm.nzna.projects.qit.gui.MultiEntryDlg.setVisible(MultiEntryDlg.java:523)
at com.ibm.nzna.projects.qit.gui.MultiEntryDlg.setVisible(MultiEntryDlg.java:523)
at com.ibm.nzna.projects.qit.gui.MultiEntryDlg.setVisible(MultiEntryDlg.java:523)
    etc..

有人能帮我解决这个错误吗?

这并不能直接回答您的问题。但是真的不要使用GridBagLayout。。这是一个疯狂的布局经理。查看布局组件所需编写的代码量。在我看来,这就是为什么许多人不再编写Swing应用程序的原因

而是使用jgoodies表单布局。这是:

如果你没听说过的话。。这是一个非常简单的布局管理器。可以将列和行规格指定为简单字符串。您可以使用库中现有的PanelBuider或FormBuilder,也可以自己制作一个。我在这里做了一个:


实际的例外情况是什么?引发异常的行是哪一行?为了更快地获得更好的帮助,请发布一个。好的,让我修改我的程序,并更新它。在
Str.getStr(Str\u ok)
方法中发生了什么?有无限循环吗?你能让你的例子运行吗?Str.getStr(Str_OK)非常好。。。我正在努力找出哪里出了问题。。。通过删除整个代码,就是在重新编写它