2012-02-16 7 views
0

그리드 가방 레이아웃 관리자를 사용하여 mutlientry 대화 상자를 쓰고 있는데,이 프로그램을 실행하려고 할 때 나는 결코 만나지 못한 이상한 오류를 보여줍니다.GridBagLayout 스윙 오류

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.. 

누구든지이 오류를 도와 줄 수 있습니까?

+0

실제 예외는 무엇입니까? 어떤 예외가 발생합니까? – unholysampler

+0

더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –

+0

ok 내 프로그램을 수정하고 업데이트하겠다. – Mike

답변

0

귀하의 질문에 직접 대답하지 않습니다. 하지만 실제로는 GridBagLayout .. 미친 layoutmanager를 사용하지 마십시오. 구성 요소 레이아웃을 작성하는 데 필요한 코드의 양을 살펴보십시오. IMO, 왜 많은 사람들이 Swing 응용 프로그램을 쓰지 않는 것으로부터 벗어난 이유입니다.

대신 jgoodies 양식 레이아웃을 사용하십시오. 여기있다 : http://www.jgoodies.com/freeware/forms/

그것에 대해 듣지 못했다면 .. 매우 간단한 레이아웃 관리자. 열 및 행 사양을 간단한 문자열로 지정할 수 있습니다. 라이브러리에 기존 PanelBuider 또는 FormBuilder를 사용하거나 자신 만의 PanelBuilder를 만들 수 있습니다. 나는 여기에 하나를 만들었습니다 :

http://code.google.com/p/swingobjects/source/browse/SwingObjects/src/org/aesthete/swingobjects/view/SwingObjFormBuilder.java