title: Jcheckbox always returnig false in Swing Java
body: <p>I am using Java and Swing, all I want to de is to test if the Jcheckbox is selected and if so adding its text to a list of Strings, the problem is that the <strong>isSelected</strong> fuction is always returning False even if the checkbox is selected.
  Here is the code I wrote:</p>
  
  <pre><code>List&lt;JCheckBox&gt; checkBoxes = new ArrayList&lt;JCheckBox&gt;();
  List&lt;String&gt; infos = new ArrayList&lt;String&gt;();
  </code></pre>
  
  
  
  <pre><code>String sql = "select NAME from drugs ";
  pre=con.prepareStatement(sql); 
  res=pre.executeQuery(); 
  while(res.next()){
      checkBoxes.add(new JCheckBox(res.getString("NAME")));
      panel.add(new JCheckBox(res.getString("NAME")));
  }; 
  for (JCheckBox checkBox : checkBoxes) {
      if (checkBox.isSelected()) {
          infos.add(checkBox.getText());
      }
  }
  </code></pre>