ButtonGroup + JRadioButton (Java 5): Como deixar todos os radios desmarcados

Olá pessoal!
Preciso criar um grupo de radio buttons que tenha a seguinte peculiaridade: Ao clicar em um radio que já esteja selecionado, este deve ser desmarcado, fazendo com que nenhum radio do grupo esteja selecionado.
Inocentemente, tentei dar um setSelected passando false (tanto no radio, quanto em seu modelo, quanto pelo button group) mas o radio não era desmarcado.
Na API do ButtonGroup do Java 6, beleza: Tem um método lá, se não me engano, que faz isso de uma vez (clearSelection ou algo assim…). Porém, meu projeto é em Java 5, e o Button Group dessa versão da linguagem não tem esse método.
Arranjei uma solução mas fiquei me sentindo meio burro… Tive que esvaziar o button group, desmarcar o radio selecionado, e então devolver os radios previamente retirados ao ButtonGroup… Funcionou, mas isso está me cheirando a POG…
Existe uma solução menos zoada que esta?

Valeu pessoal!

Mantu,

você tentou escrever uma subclasse? algo assim:

[code]import java.io.Serializable;
import java.util.Enumeration;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;

public class MyButtonGroup extends javax.swing.ButtonGroup implements Serializable {

/**
 * The current selection.
 */
ButtonModel selection = null;

/**
 * Creates a new <code>ButtonGroup</code>.
 */
public MyButtonGroup() {
}

/**
 * Adds the button to the group.
 * @param b the button to be added
 */
@Override
public void add(AbstractButton b) {
    if (b == null) {
        return;
    }
    buttons.addElement(b);

    if (b.isSelected()) {
        if (selection == null) {
            selection = b.getModel();
        } else {
            b.setSelected(false);
        }
    }

    b.getModel().setGroup(this);
}

/**
 * Removes the button from the group.
 * @param b the button to be removed
 */
@Override
public void remove(AbstractButton b) {
    if (b == null) {
        return;
    }
    buttons.removeElement(b);
    if (b.getModel() == selection) {
        selection = null;
    }
    b.getModel().setGroup(null);
}

/**
 * Returns all the buttons that are participating in
 * this group.
 * @return an <code>Enumeration</code> of the buttons in this group
 */
@Override
public Enumeration<AbstractButton> getElements() {
    return buttons.elements();
}

/**
 * Returns the model of the selected button.
 * @return the selected button model
 */
@Override
public ButtonModel getSelection() {
    return selection;
}

/**
 * Sets the selected value for the <code>ButtonModel</code>.
 * Only one button in the group may be selected at a time.
 * @param m the <code>ButtonModel</code>
 * @param b <code>true</code> if this button is to be
 *   selected, otherwise <code>false</code>
 */
@Override
public void setSelected(ButtonModel m, boolean b) {
    if (b && m != null && m != selection) {
        ButtonModel oldSelection = selection;
        selection = m;
        if (oldSelection != null) {
            oldSelection.setSelected(false);
        }
        m.setSelected(true);
    }
}

/**
 * Returns whether a <code>ButtonModel</code> is selected.
 * @return <code>true</code> if the button is selected,
 *   otherwise returns <code>false</code>
 */
@Override
public boolean isSelected(ButtonModel m) {
    return (m == selection);
}

/**
 * Returns the number of buttons in the group.
 * @return the button count
 * @since 1.3
 */
@Override
public int getButtonCount() {
    if (buttons == null) {
        return 0;
    } else {
        return buttons.size();
    }
}

@Override
public void clearSelection() {
    if (getSelection() != null) {
        ButtonModel oldSelection = getSelection();
        selection = null;
        oldSelection.setSelected(false);
    }
}

}[/code]

Os fontes são da classe original do sdk 6.

fw