RadioGroupId doesn't work between different components

According to me RadioButtons doesn’t work between RadioButtons objects instantiated in different components objects.

Following tutorial “Radio Buttons and Checkerboxes”, I created on my MainComponent 2 RadioButtons and I gave them the same RadioGroupId, after I tried to create another Component class (creating .cpp file and .h file in Projucer) where I instantiated other RadioButtons and also to them I gave the same RadioGroupId owned by my two objects in Main Component. When I build the app however it works only between objects contained in the same component, so if in MainComponent I select the first RadioButton, the second one turn off, but when I turn on any RadioButton contained on the other component class the RadioButtons of the MainComponent Class remains selected.

It’s right or there’s a way to select only one RadioButton also between different component classes?

Thank you in advice!

The docs for setRadioGroupId say:

To find other buttons with the same ID, this button will search through its sibling components for ToggleButtons, so all the buttons for a particular group must be placed inside the same parent component.

If you want to spread the same radio group across different components, you’ll need to find some other solution. Perhaps something like this:

  • Use a juce::Value to store some information about the selected button (its name or some other unique id)
  • When a button is pressed, update the value with the id of the selected button
  • When the Value changes (use the Listener system to receive change notifications), compare the value to the id of each button, and only leave a button selected if its id matches the value.
1 Like

Thank you reuk! I’ll try this way!