0

I am trying to move all the selected checkboxes from panel1 into panel2 and also removing the checkboxes from panel1 after the transfer. I made two arraylist to hold the checkboxes

ArrayList<JCheckBox> todo_box = new ArrayList<JCheckBox>();
ArrayList<JCheckBox> inprogress_box = new ArrayList<JCheckBox>();

and when the user clicks on the button I have this,

for(JCheckBox cb : todo_box)
{
    if(cb.isSelected() )
    {  
        inprogress_box.add(cb);
        jPanel2.add(cb);
        jPanel2.revalidate();
        cb.setVisible(false);
        todo_box.remove(cb);
        jPanel1.remove(cb);
        jPanel1.revalidate();
    }
}     

Not sure if I'm on the right track since I'm getting an exception error inside netbean.

  • 1
    Always include any exceptions/error messages you get in the question. Anyway, adding a component to a container removes it from any previous container. – kiheru May 16 '15 at 08:24
  • If I comment out jPanel1.remove(cb), I get this really long exception error. http://pastebin.com/BALW9wkM – CrunchyTaco May 16 '15 at 09:30
  • 1
    Ahh... concurrent modification. The problem is that you're iterating over `todo_box`, and modifying it within the loop. You can only modify the list if you do it through the iterator, see for example [here](http://stackoverflow.com/questions/223918/iterating-through-a-list-avoiding-concurrentmodificationexception-when-removing). – kiheru May 16 '15 at 09:37
  • Post the exception in your question by editing it, not by linking to an external site. – user1803551 May 16 '15 at 12:40
  • If you want help with moving components you need to post an example code that we can run ourselves. It seems that right now too many things are wrong. – user1803551 May 16 '15 at 12:42

0 Answers0