removing all buttons from buttongroup
I'm trying to remove all the buttons from a buttonGroup but I'm having problems with the argument of the remove() method defined in the API:
Code :
for(int i = 0; i < RadioButtonsGroup.getButtonCount(); i++){
RadioButtonsGroup.remove......???
}
It seems there is no method to remove a button by index, any suggestion for a beginner?
Re: removing all buttons from buttongroup
RadioButtonsGroup.remove ( AbstractButton ab );
How do you store your buttons after creating them? In an array? ArrayList? Iterate the collection and remove index for each.
Re: removing all buttons from buttongroup
the buttons are created from a List returned from port.getAvailablePorts(): (method from rxtx serial class)
Code :
for (int i = 0; i < port.getAvailablePorts().size(); i++){
JRadioButtonMenuItem e = new JRadioButtonMenuItem(port.getAvailablePorts().get(i));
RadioButtonsGroup.add(e);
menuItem.add(e);}
when I want to refresh the serial ports list, first I need to clear the button group, then rebuild it with the new buttons, but I can't clear it using remove() with values from port.getAvailablePorts() because they can change at any time.
I will try to store the buttons in a separate ArrayList, so I will feed the remove() method with its values, then clear the Arraylist, fill the ArrayList with the new values from port.getAvailablePorts(), create and add the buttons to the button group.