0

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?

DanielLC
  • 5,801
  • 5
  • 18
  • 16
  • 1
    So, 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 Answers1

0

Is there anything I can do besides remove each element from the button group one at a time?

  1. Manually removing buttons seems simple enough to do.

  2. Or you could extend ButtonGroup and create a removeAllButtons() method. By extending ButtonGroup. You will have access to the Vector that holds all the buttons in the group. Then you just invoke the removeAllElement()method of the Vector.

  3. 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