title: JCheckbox not removing correctly
body: <p>I asked a question this morning about JCheckbox but was told to narrow down the problem.
  After several debugging, I kind of narrowed down to the problem but still was not able to solve.</p>
  
  <p>It seems that if I select a JCheckbox and another JCheckbox that is not the subsequent one, both will be removed.
  (E.g if I select JCheckbox at position 0 and 2 or 3, both will be removed).</p>
  
  <p>But if I select a JCheckbox and then select the subsequent one, it will only delete the first JCheckbox.(E.g if I select JCheckbox at position 0 and 1, only JCheckbox at position 0 will be removed). </p>
  
  <p>How can I resolve this issue?   </p>
  
  <pre><code>import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.ArrayList;
  import java.util.List;
  import javax.swing.JButton;
  import javax.swing.JCheckBox;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  @SuppressWarnings("serial")
  public class CheckBoxTest extends JPanel {
  
      JButton deleteBtn = new JButton("Delete!");
      List&lt;JCheckBox&gt; checkboxes = new ArrayList&lt;JCheckBox&gt;();
  
      public CheckBoxTest() {
          setLayout(new GridLayout(0, 1));
          for(int i = 0; i &lt; 4; i++) {
              checkboxes.add(new JCheckBox());
              checkboxes.get(i).setText("text" + i);
              add(checkboxes.get(i));
          }
          add(deleteBtn);
          deleteBtn.addActionListener(new DeleteBtnActionPerformed());
      }
  
      public class DeleteBtnActionPerformed implements ActionListener {   
  
          @Override
          public void actionPerformed(ActionEvent e) {
              for(int i = 0; i &lt; checkboxes.size(); i++) {
                  if(checkboxes.get(i).isSelected()) {
                      System.out.println(checkboxes.get(i).getText() + " was deleted");
                      checkboxes.remove(i);       
                  }
              }   
          } 
      }
  
      public static void main(String[]args) { 
          JFrame frame = new JFrame();
          frame.add(new CheckBoxTest());
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.pack();
          frame.setSize(400,250);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
      }
  }
  </code></pre>