title: Display buttons properly gridbaglayout
body: <p>Im making a quiz application. When a team pushed their button the administrator of the quiz gets a pop up jframe that a team has pressed their button, in that JFrame there is the question and the answers, if the team answered correct he can go to the next question, if they didn't he can resume the question. See image : <a href="http://imgur.com/EtzH8Hq" rel="nofollow">http://imgur.com/EtzH8Hq</a> // sorry I don't have 10 reputation yet.</p>
  
  <p>Since most of the text in this JFrame is dynamic ( you don't know how many answers/options a question has, etc ), i used gridbaglayout for this. </p>
  
  <p>Everything displayed nicely untill i added the buttons, i want the resume button and the calculate button in the bottomright corner, or 1 in the bottom left corner and the other in the bottom  right corner. I tried doing this in my code but it isn't placed where it should be.</p>
  
  <p>Any help?</p>
  
  <p>Here is the code where i try to do this :</p>
  
  <pre><code>public class GiveScoreView extends JFrame implements View {
  Observable $model;
  Controller $controller;
  
  private Question $question; /* Saves the question that is passed by the update */
  
  /*GUI elements */
  ArrayList&lt;JLabel&gt; $answerLabels;
  ArrayList&lt;JCheckBox&gt; $checkBoxes;
  JLabel $questionLabel;
  JLabel $teamPressedLabel;
  
  /* 2 buttons to resume/end the question */
  JButton $resumeButton;
  JButton $calculateButton;
  
  public GiveScoreView(Observable model, Controller controller) {
  
      setModel(model);
      setController(controller);
  
      $answerLabels = new ArrayList&lt;JLabel&gt;();
      $checkBoxes = new ArrayList&lt;JCheckBox&gt;();
      $questionLabel = new JLabel();
  
      $teamPressedLabel = new JLabel();
  
      $question = null;
  
      $resumeButton = new JButton("Resume question"); /* TODO messagebundle */
      $calculateButton = new JButton("Calculate score"); /* TODO messagebundle */
  
      /* Add actionlisteners to the buttons */
      $resumeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              if($question != null){
                  if($question.getMediaPath() != null &amp;&amp; QuizSoftwareModel.$vlcPath != null) /* If there is an audio/video piece */
                      ((GiveScoreController)getController()).resumeMP(); /* Resume the mediaplayer if there is an audio/video piece */
  
                  ((GiveScoreController)getController()).resumeQuestion(); /* Resume the question */
                  closeFrame(); /* Close the frame */
              }
          }
      });
  
      $calculateButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              if($question != null){
                  if($question.getMediaPath() != null &amp;&amp; QuizSoftwareModel.$vlcPath != null) /* If there is an audio/video piece */
                      ((GiveScoreController)getController()).closeMP(); /* Close the mediaplayer */
                  ((GiveScoreController)getController()).nextQuestion(); /* Go on to the next question */
                  closeFrame(); /* Close the frame */
              }
          }
      });
  
  
      initializeFrame();
  }
  
  /**
   * Initializes the frame
   */
  private void initializeFrame() {
      setTitle("Give a score to the teams"); /* TODO languagebundle, Change the title of the frame */
  
      getContentPane().setLayout(new GridBagLayout());/* Set the layout to gridbaglayout */
  
      addWindowListener(new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
              dispose();
          }
      });
  
      pack();
      setVisible(false); /* Don't display it on default */
  
  }
  
  @Override
  public void update(Observable arg0, Object arg1) {
      $question = (Question) arg1;
  
      /* Now we need to display this frame */
      if(((QuizModel) getModel()).getDisplayScoreView()){
          $teamPressedLabel.setText("Team " + Integer.toString(((QuizModel) getModel()).getTeamPressed()) + " is ready to answer!"); /* TODO messagebundle */
          $teamPressedLabel.setFont(new Font("Serif", Font.PLAIN, 34)); /* Change the font */
          displayScoreView();
          setVisible(true); /* Now display the JFrame */
      }
  }
  
  
  
  
  private void displayScoreView() {
      Multipleanswer multipleanswerQuestion; /* a multiple answer question to display the multipleanswer questions */
      Multiplechoice multiplechoiceQuestion; /* a multiple choice question to display the multiplechoice questions */
      ArrayList&lt;String&gt; answers = null;
  
      GridBagConstraints c = new GridBagConstraints();
  
      /* Set the position of the JFrame so it's centered */
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  
      // Determine the new location of the window
      int w = getSize().width;
      int h = getSize().height;
      int x = (dim.width - w) / 2;
      int y = (dim.height - h) / 2;
      int i = 0;
  
      // Move the window
      setLocation(x - 150, y - 150);
  
      /* Set size */
      setSize(550, 300);
  
  
      /* If the question isn't empty */
      if (!($question == null)) {
          c.anchor = GridBagConstraints.NORTHWEST; 
  
          $questionLabel.setText($question.getQuestion()); /* Set the text of the JLabel to the question itself */
          $questionLabel.setFont(new Font("Serif", Font.PLAIN, 26)); /* Change the font */
  
          getContentPane().add($teamPressedLabel,c); /* Add the label to the JFrame, the team that has pressed it's button */
  
          c.weighty = 1.0;
  
          /* Display the question under the team pressed text */
          c.gridx = 0;
          c.gridy = 1;
  
          getContentPane().add($questionLabel,c); /* Add the label to the JFrame, the question itself */
  
          /* If the type of the question is multipleanswer */
          if ($question.getType() == QuestionType.MULTIPLEANSWER) {
  
              /* Cast it to multipleanswer question */
              multipleanswerQuestion = (Multipleanswer) $question;
  
              /* Get the answers */
              answers = multipleanswerQuestion.getAnswers();
          } else if ($question.getType() == QuestionType.MULTIPLECHOICE) {
  
              /* Cast it to multiplechoice question */
              multiplechoiceQuestion = (Multiplechoice) $question;
  
              /* Get the answers */
              answers = multiplechoiceQuestion.getAnswers();
          }
  
          /* Speed questions don't show answers so we only display answers if it's not a speed question */
          if ($question.getType() != QuestionType.SPEED) {
              /* Make a JLabel and JCheckBox for each answer */
              for (i = 0; i &lt; answers.size(); i++) {
                  $answerLabels.add(new JLabel(answers.get(i))); /* Make a new JLabel with answer string as text */
                  $checkBoxes.add(new JCheckBox()); /* Make a new JCheckBox */
  
                  $answerLabels.get(i).setFont(new Font("Serif", Font.PLAIN, 16));
                  c.gridx = 0;
                  c.gridy = i + 2;
                  getContentPane().add($answerLabels.get(i),c); /* Add the label to the JFrame */
                  c.gridx = 1;
                  c.gridy = i + 2;
                  getContentPane().add($checkBoxes.get(i),c); /* Add the checkbox to the JFrame */
  
              }
          }
  
          /* Place the buttons */
          c.gridx = 0;
          c.gridy = i + 2;
  
  
          getContentPane().add($resumeButton);
  
          c.gridx = 1;
          c.gridy = i + 2;
  
          getContentPane().add($calculateButton);
      }
  }
  
  
  /**
   * Closes the JFrame
   */
  protected void closeFrame() {
      this.dispose();
  
  }
  </code></pre>