2013-04-13 3 views
-1

내 끝이 아닌 사실 때문에 내가 알고있는 문제로 인해 정말로 화가났습니다! Eclipse에서 현재 프로젝트를 실행할 때마다 디스플레이가 매번 다릅니다! 내 말은, 한 번 실행하면 구성 요소 중 세 개만 표시된다는 것입니다. 다시 실행하면 더 많이 표시됩니다. 다시 실행하면 등 3 개가 표시됩니다. 도대체 무슨 일이 벌어지고 있는지. 이것은 메인 문자열 args에서 실행중인 코드입니다.Eclipse는 매번 다르게 표시됩니다.

 JFrame frame = new JFrame("Survey"); 
    frame.setSize(500, 500); 
    frame.setVisible(true); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    JPanel panel = new JPanel(new GridBagLayout()); 
    panel.setBackground(Color.GRAY); 
    frame.add(panel, BorderLayout.NORTH); 
    GridBagConstraints c = new GridBagConstraints(); 

    JLabel label1 = new JLabel("First name:"); 
    c.gridx = 0; 
    c.gridy = 0; 
    c.insets = new Insets(5, 5, 5, 5); 
    panel.add(label1, c); 

    JLabel label2 = new JLabel("Last name:"); 
    c.gridx = 0; 
    c.gridy = 1; 
    panel.add(label2, c); 

    JTextField text1 = new JTextField(10); 
    c.gridx = 1; 
    c.gridy = 0; 
    panel.add(text1, c); 

    JTextField text2 = new JTextField(10); 
    c.gridx = 1; 
    c.gridy = 1; 
    panel.add(text2, c); 

    JLabel label3 = new JLabel("What is your favorite sport:"); 
    c.gridx = 0; 
    c.gridy = 2; 
    c.gridwidth = 2; 
    panel.add(label3, c); 

    String[] combobox = {"Basketball", "Soccor", "Other"}; 
    JComboBox cbx = new JComboBox(combobox); 
    cbx.setPreferredSize(new Dimension(150, 20)); 
    c.gridx = 0; 
    c.gridy = 3; 
    panel.add(cbx, c); 

    JLabel label4 = new JLabel("Comments about yourself:"); 
    c.gridx = 0; 
    c.gridy = 4; 
    panel.add(label4, c); 

    JTextArea area = new JTextArea(); 
    area.setPreferredSize(new Dimension(185, 100)); 
    c.gridx = 0; 
    c.gridy = 5; 
    c.gridheight = 5; 
    panel.add(area, c); 

    JButton submit = new JButton("Submit"); 
    submit.setPreferredSize(new Dimension(20, 20)); 
    c.gridx = 0; 
    c.gridy = 6; 
    panel.add(submit, c); 
+0

폼을 실행 한 다음 폼의 크기를 조정하면 모든 구성 요소가 다시 나타납니다. 어떻게 해결합니까? –

+0

문제가 해결되었습니다. frame.revalidate();를 추가해야합니다. 모든 코드의 끝에. 자바는 당신이 그런 절름발이를 할 필요가있는 언어라고 생각합니다. –

답변

관련 문제