From what I understand, if you want to have to select one option, you put it in a ButtonGroup, and if you don't, you don't use a ButtonGroup. But I want it so that multiple can be selected but only if you selected something else in another area. Is there anything I can do besides remove each element from the button group one at a time?
Asked
Active
Viewed 80 times
0
-
1So, if I understand what you're asking, you want a group of JButtons where only one can be selected. If you select something else, then the group of JButtons allow multiple selections. Is this correct? What's the something else selected? – Gilbert Le Blanc Dec 06 '20 at 10:14
1 Answers
0
Is there anything I can do besides remove each element from the button group one at a time?
Manually removing buttons seems simple enough to do.
Or you could extend
ButtonGroup
and create aremoveAllButtons()
method. By extendingButtonGroup
. You will have access to theVector
that holds all the buttons in the group. Then you just invoke theremoveAllElement()
method of the Vector.You could create a custom
ButtonModel
. See: https://stackoverflow.com/a/44183140/131872 as an example of this approach. You could modify the logic such that a size value of "-1" indicates there is no selection limit.

camickr
- 321,443
- 19
- 166
- 288