Radio buttons not working as expected (even in the Juce example)

Hi All,

I’ve been trying to have 3 TextButtons which I are part of a RadioGroup and therefore only one can be ‘On’ at a given time:

class OrderSelect : public Component
    TextButton firstOrder {"1st Order"};
    TextButton secondOrder {"2nd Order"};
    TextButton thirdOrder {"3rd Order"};
        firstOrder.setRadioGroupId (1001);
        secondOrder.setRadioGroupId (1001);
        thirdOrder.setRadioGroupId (1001);
        firstOrder.setToggleState(true, NotificationType::dontSendNotification);
        secondOrder.setToggleState(false, NotificationType::dontSendNotification);
        thirdOrder.setToggleState(false, NotificationType::dontSendNotification);
    void resized() override
        int noOfOrders = 3;
        auto buttonHeight =  getHeight() / noOfOrders;
        firstOrder.setBounds (0, 0, getWidth(), buttonHeight );
        secondOrder.setBounds(0, buttonHeight, getWidth(), buttonHeight );
        thirdOrder.setBounds (0, buttonHeight*2, getWidth(), buttonHeight );

This however results in 3 buttons which can all be clicked to ‘On’ and never turned off. I’ve checked the Juce example ( and when I build that it seems to suffer the same issue?

Any help?

The only think I can see is you do not set a buttonWidth, but you call it in resized(). Components nog having proper heights and widths is a common mistake that leads to unpredictable behavoir - I’ve wasted many hours because of such errors… Try a setSize in the constructor.

Oh and why is resized() private?

Hi tomto66, thanks for the reply! setSize() has made no difference. In the example Juce provide the two issues you’ve mentioned are corrected but the overall problem is still there. The issue goes away if I comment out .setRadioGroupId(), however this defeats the point…
Would love someone to try the linked example and see if they suffer the same issue?

I copied your code into an empty Application and it worked as expected.
However I noticed, that the colour of the on state is very subtly different from the off state.

You can make it more obvious by adding these two lines to your constructor (the values will be inherited to the child components):

    getLookAndFeel().setColour (TextButton::buttonColourId, Colours::red);
    getLookAndFeel().setColour (TextButton::buttonOnColourId, Colours::green);

Hi Daniel,

Thanks for the response. I’ve modified the Juce example code and added your suggestion but I’m still getting the same issue.

class MainContentComponent   : public Component
    enum RadioButtonIds
        GenderButtons = 1001

        addAndMakeVisible (genderLabel);

        maleButton  .onStateChange = [this] { updateToggleState (&maleButton,   "Male");   };
        femaleButton.onStateChange = [this] { updateToggleState (&femaleButton, "Female"); };
        maleButton  .setToggleState (true, dontSendNotification);
        femaleButton.setToggleState (false, dontSendNotification);
        maleButton  .setClickingTogglesState(true);
        maleButton  .setRadioGroupId (GenderButtons);
        femaleButton.setRadioGroupId (GenderButtons);
        getLookAndFeel().setColour (TextButton::buttonColourId, Colours::red);
        getLookAndFeel().setColour (TextButton::buttonOnColourId, Colours::green);
        addAndMakeVisible (maleButton);
        addAndMakeVisible (femaleButton);
        setSize (400, 300);

    ~MainContentComponent() {}
    void paint (Graphics& g) override {
        g.fillAll (Colours::darkgrey);
    void resized() override
        genderLabel .setBounds (10, 10, 120, 20);
        maleButton  .setBounds (20, 40, 130, 20);
        femaleButton.setBounds (20, 70, 130, 20);

    void updateToggleState (Button* button, String name)
        auto state = button->getToggleState();
        String stateString    = state ? "ON" : "OFF";
        String selectedString = state ? " (selected)" : "";

        Logger::outputDebugString (name + " Button changed to " + stateString);
        button->setButtonText (name + selectedString);

    Label genderLabel         { {}, "I identify my gender as..."};
    TextButton maleButton     { "Male" },
               femaleButton   { "Female" };

Each button can be selected and then shows the ‘(selected)’ in text next to it… Only both can go into that state at the same time and then never changed back to unselected

Unfortunately your code works here without problems… I’m afraid I have no idea, what’s going wrong:

Work fine for me too… (I’m on OS X and U ?), suggest delete and reload the juce library ?

It’s working as expected for me too. What version of JUCE are you using?

Using Juce 5.4.1

I’m not sure what else could be the issue then, it seems to be working fine. Can you check the widgets demo in the DemoRunner app? There is a set of radio buttons on the “Buttons” tab here which should be behaving the same:


Okay great, I’ve ran the widgets demo and it works as expected for me. I’m away until Saturday but I will copy over the relevant lines from that demo into my project and check whether the issue persists. Thanks

And if you build the widgets demo, is it ok too ?