How do I clear the selection in a ButtonGroup such that no elements of the associated set of abstract buttons are selected?

itro picture itro · Oct 23, 2012 · Viewed 10.1k times · Source

I have created 5 radioButton group. I want user clear all group in one click. i use java 1.5.

Does any one know how to do it?

public void actionCommandCLEAR() {
        timeGroup.setSelected(timeGroup.getSelection(),false);
        dateGroup.setSelected(dateGroup.getSelection(),false);
        docGroup.setSelected(docGroup.getSelection(),false);
        socGroup.setSelected(socGroup.getSelection(),false);

}

Answer

user1766873 picture user1766873 · Oct 23, 2012
timeGroup.clearSelection();
dateGroup.clearSelection();
docGroup.clearSelection();
socGroup.clearSelection();

for java 1.5 we need to code clearSelection ourselves:

void cleartSelection(ButtonGroup bg) {
 Enumeration<AbstractButton> e =bg.getElements(); 
    while(e.hasMoreElements()) {
        AbstractButton b = e.nextElement();
        b.setSelected(false);
    }
}

and

clearSelection(timeGroup);