-1

I am attempting to have four jradiobuttons that are all connected. There are two teams that each have the option of left or right. A team should only have one of the options selected, while at the same time the team's should not have the same option selected (ie. Both left or both right). I tried using four jradiobutton groups, placing the buttons for the team in a group as well as having the lefts in a group and the rights in a group.

For example, if I have four JRadioButtons A,B,C,D,

A B

C D

I need A and B to be grouped, C and D to be grouped, A and C to be grouped, and B and D to be grouped, so that the only possible combinations are A and D being selected, or B and C.

ekad
  • 14,436
  • 26
  • 44
  • 46
Ian Pierce
  • 11
  • 1

1 Answers1

0

You can't really just use ButtonGroup for this. It's a bit more complicated.

I would have a ButtonGroup for the two horizontal lines like so :

ButtonGroup bG = new ButtonGroup();
bg.add(A);
bg.add(B);

ButtonGroup bG = new ButtonGroup();
bg.add(C);
bg.add(D);

And then add an actionlistener on the radio buttons. The actionListener will listen on all radio buttons. If A is clicked then move selection to D in the lower row. Or if C is selected move upper row selection to B. Etc.

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225