title: Getting JCheckBox selected box value
body: <p>I want to ask is there a way to get information from JCheckBox without actionListener. In my code I scan a file of strings and each line has data which, if selected, should be added to an array in my program. Problem is that i will never know how many JCheckBoxes I will have, it depends from file.</p>
  
  <p>So, my question is how to put selected strings to an array (or list) with a press of a button (ok) so i could do something else with them (in my case i need to get data from file or from hand input and put it in a red-black tree, so I will need to push selected strings to my putDataInTheTree method).</p>
  
  <p>EDIT: Also, is it possible not to show those JCheckBoxes that already has been added to the program? I.E. if i choose fluids, next time I call input method fluids wont show in my panel?</p>
  
  <p>Thanks in advance!</p>
  
  <p>How it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/wFuAl.png" alt="enter image description here"></p>
  
  <p>My code is so far:</p>
  
  <pre><code>public void input() {
      try {
          mainWindow.setEnabled(false);
          fromFile = new JFrame("Input from file");
          fromFile.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
          fromFile.setLayout(new BorderLayout());
          fromFile.setSize(300,200);
          panelFromFile = new JPanel();
          panelFromFile.setLayout(new java.awt.GridLayout(0,1));
          JScrollPane scrollPane2 = new JScrollPane(panelFromFile); 
          scrollPane2.setMaximumSize(new Dimension(300, 180));
  
          FileReader File = new FileReader(data);
          BufferedReader Buffer = new BufferedReader(File); 
          while ((info = Buffer.readLine()) != null) {
              if (info != null) {
                  JCheckBox check = new JCheckBox(info);
                  panelFromFile.add(check);
              }
          }
          ok = new JButton("ok");
          ok.addActionListener(this);
          fromFile.add(scrollPane2, BorderLayout.CENTER);
          fromFile.add(ok, BorderLayout.SOUTH);
          fromFile.setLocationRelativeTo(null);
          fromFile.setResizable(false);
          fromFile.setVisible(true);
      }
      catch(Exception e) {
          text.append("Error in INPUT method");
          text.append(System.getProperty("line.separator"));
      }
  }
  </code></pre>