In short yes... without a ButtonGroup
everything works as expected, however:
You should generally initialize a group of radio buttons so that one is selected. However, the API doesn't enforce this rule — a group of radio buttons can have no initial selection. Once the user has made a selection, exactly one button is selected from then on.
So basically the only time no JToggle
button can be selected is at start up. The minute one is selected we can only change the selected, we cannot unselect everything.
And if we think about it logically it makes sense, imagine we have 2 options yes or no... atleast one option must have been selected/enforced at the time. Or you must add more alternatives like yes, no and still thinking (dumb example but im not good at explaining).
but there is always a work around:
There's no supported API for un-selecting all the buttons. However, if you really want to un-select all the buttons (not that it's recommended), calling setSelected(null, true)
on the ButtonGroup
should do the trick.
Reference: